spring-aop
2023-04-01 15:45:19 0 举报
AI智能生成
登录查看完整内容
常见的切面表达式
作者其他创作
大纲/内容
定义:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)
execution(public * *(..))
全部的public方法
execution(* set*(..))
任意以set开头的方法
execution(* com.xyz.service.AccountService.*(..))
The execution of any method defined by the AccountService interface(定义在AccountService接口里的任意方法):
execution(* com.xyz.service.*.*(..))
The execution of any method defined in the service package(service包里的任意方法):
execution(* com.xyz.service..*.*(..))
The execution of any method defined in the service package or one of its sub-packages(service包和子包里的任意方法):
示例
execution
within(com.xyz.service.*)
Any join point (method execution only in Spring AOP) within the service package(springAop中,service包里的方法):
within(com.xyz.service..*)
Any join point (method execution only in Spring AOP) within the service package or one of its sub-packages:
within
this(com.xyz.service.AccountService)
Any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:
this
target(com.xyz.service.AccountService)
Any join point (method execution only in Spring AOP) where the target object implements the AccountService interface:
target
args(java.io.Serializable)
Any join point (method execution only in Spring AOP) that takes a single parameter and where the argument passed at runtime is Serializable:
args
@target(org.springframework.transaction.annotation.Transactional)
Any join point (method execution only in Spring AOP) where the target object has a @Transactional annotation:
@target
@args(com.xyz.security.Classified)
@args
@within(org.springframework.transaction.annotation.Transactional)
Any join point (method execution only in Spring AOP) where the declared type of the target object has an @Transactional annotation:
@within
@annotation(org.springframework.transaction.annotation.Transactional)
Any join point (method execution only in Spring AOP) where the executing method has an @Transactional annotation:
@annotation
切点指示符
组合使用
匹配任意的返回类型
如:execution(public * *(..))
返回类型
*通配符作为所有或者部分命名模式
全限定名
*
包含子包
如:
匹配任意数量,任意类型参数的方法
参数()里
..
如:com.Account+.*.*()
匹配子类型
+
()匹配了一个不接受任何参数的方法。
(..)匹配了一个接受任意数量参数的方法(零或者更多)
(*)匹配了一个接受一个任何类型的参数的方法
()
@Aspect支持
spring-aop
收藏
收藏
0 条评论
回复 删除
下一页