Spring之AOP小结(二)@Pointcut注解
Spring之AOP小结(二)@Pointcut注解
@Pointcut的格式:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)throws-pattern?)
各个pattern含义:
- 修饰符匹配(modifier-pattern?)
- 返回值匹配(ret-type-pattern)可以为*表示任何返回值,全路径的类名等
- 类路径匹配(declaring-type-pattern?)
- 方法名匹配(name-pattern)可以指定方法名 或者 代表所有, set 代表以set开头的所有方法
- 参数匹配((param-pattern))可以指定具体的参数类型,多个参数间用“,”隔开,各个参数也可以用“”来表示匹配任意类型的参数,如(String)表示匹配一个String参数的方法;(,String) 表示匹配有两个参数的方法,第一个参数可以是任意类型,而第二个参数是String类型;可以用(…)表示零个或多个任意参数
- 异常类型匹配(throws-pattern?)
- 其中后面跟着“?”的是可选项
@Pointcut表达式示例:
匹配所有方法
execution( (..))
表示在UserMangeImpl类下的所有方法
@Pointcut(“execution( com.spring.two.UserMangeImpl.(..))”)
匹配com.savage.server.UserService中所有的公有方法
execution(public com. savage.service.UserService.(..))
任何一个以set开始的方法,不仅仅是set,save、update也都行。
@Pointcut(“execution( set(..))”)
在指定包下的所有方法
@Pointcut(“execution( com.spring..*(..))”)
还没有评论,来说两句吧...