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