文章目录
spring语法
execution
方法表达式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern/name-pattern(param-pattern) throws-pattern?)
- 修饰符匹配(modifier-pattern?):可以省略。代表匹配任意修饰符方法;或者显示指定public、private
- 返回值匹配(ret-type-pattern):不可省略。可以为*,表示任何返回值;或者全路径的类名
- 类路径匹配(declaring-type-pattern)/方法名匹配(name-pattern):两种任选一个,不可省略。全路径类名或者正则方法名;或者*,代表所有。
- 参数匹配((param-pattern)):不可省略。() 匹配一个不需要参数的方法;(…) 匹配任何数量(零或更多)的参数;(*) 模式匹配一个需要任何类型的参数的方法;(*,java.lang.String) 表示匹配有两个参数的方法,第一个参数可以是任意类型,而第二个参数是String类型;
- 异常类型匹配(throws-pattern?):可以省略,代表匹配任意异常,或者全路径显示指定。
- 示例:
execution(* com.hytech.user.service.UserOuterService.*(..))UserOuterService接口所定义的任何方法的 execution execution(* com.hytech.user.service.*.*(..)):在 service 包中定义的任何方法的 execution: execution(* com.hytech.user.service..*.*(..)):在 service 包或其子包中定义的任何方法的 execution。
within
类型表达式:within(declaring-type-pattern)
- 类路径匹配(declaring-type-pattern):不可省略,全限定命名,支持正则
- 示例:
within(com.hytech.user.service.impl.UserOuterServiceImpl):过滤UserOuterServiceImpl的方法 within(com.hytech.user.service.impl.*):过滤impl包内的所有类的方法 within(com.hytech.user.service..*):过滤impl包及其子包内的所有类的方法
this
代理对象表达式:this(type)
-
数据类型匹配:当生成的代理对象可以转换为指定的类型时匹配。但需注意基于JDK接口的代理和基于CGLIB的代理生成的代理对象是不一样的。尽量用target,若必须用则指定接口类。
-
示例:
this(com.hytech.user.service.UserOuterService):当生成的代理对象可以转换为UserOuterService类型时匹配
target
目标对象表达式:target(type)
- 数据类型匹配:当被代理的目标对象可以被转换为指定的类型时则表示匹配。使用实现类匹配。
- 示例: