Spring AOP中pointcut expression表达式解析 及匹配多个条件

Spring中事务控制相关配置:

  
    
  


  
    
      
      
      
    

  


  
    
    
  

  其中的“aop:pointcut”标签中"expression"的写法规则如下:

     execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)  throws-pattern?)
    ret-type-pattern,name-pattern(param-pattern)是必须的.
    ret-type-pattern:标识方法的返回值,需要使用全路径的类名如java.lang.String,也可以为*表示任何返回值;
    name-pattern:指定方法名,*代表所有,例如set*,代表以set开头的所有方法.
    param-pattern:指定方法参数(声明的类型),(..)代表所有参数,(*)代表一个参数,(*,String)代表第一个参数为任何值,第二个为String类型.

    表达式例子如下:

  任意公共方法的执行:
    execution(public * *(..))
  任何一个以“set”开始的方法的执行:
    execution(* set*(..))
  AccountService 接口的任意方法的执行:
    execution(* com.xyz.service.AccountService.*(..))
  定义在service包里的任意方法的执行:
    execution(* com.xyz.service.*.*(..))
  定义在service包和所有子包里的任意类的任意方法的执行:
    execution(* com.xyz.service..*.*(..))
  定义在pointcutexp包和所有子包里的JoinPointObjP2类的任意方法的执行:
    execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")

  在多个表达式之间使用 ||,or表示 或,使用 &&,and表示 与,!表示 非.例如:

     
      
      
  

出处:https://www.cnblogs.com/qinyubin/p/4075466.html


详细介绍:

关于aop:pointcut的expression配制说明及JoinPoint

出处:http://blog.csdn.net/wubai250/article/details/8102194

关于aop:pointcut的expression配制说明及JoinPoint
我的示例如下,配制了多个pointcut:

       


   
   
   
   
       
       
       
   


expression说明:
expression是对方法签名的通配.本例中分为两部分
第一个空格前是说明ret-type-pattern,空格后是说明name-pattern(param-pattern),具体说明如下:
第一个*(ret-type-pattern), 表示任意返回值类型
第二个和第三个*(name-pattern), 第二个包名通配,第三个方法名通配
最后二个.. 表示通配方法可以有0个或多个参数


##################################################
以下为网上文档:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)throws-pattern?)

returning type pattern,name pattern, and parameters pattern是必须的.
ret-type-pattern:可以为*表示任何返回值,全路径的类名等.
name-pattern:指定方法名,*代表所以,set*,代表以set开头的所有方法.
parameters pattern:指定方法参数(声明的类型),(..)代表所有参数,(*)代表一个参数,(*,String)代表第一个参数为任何值,第二个为String类型.

JoinPoint实用方法说明:

java.lang.Object[] getArgs():获取连接点方法运行时的入参列表;
Signature getSignature() :获取连接点的方法签名对象;
java.lang.Object getTarget() :获取连接点所在的目标对象;
java.lang.Object getThis() :获取代理对象本身;

网上其它示例1:

第一个* 表示任意返回值类型
第二个* 表示以任意名字开头的package. 如 com.xx.
第三个* 表示以任意名字开头的class的类名 如TestService
第四个* 表示 通配 *service下的任意class
最后二个.. 表示通配 方法可以有0个或多个参数

 

网上其它示例2:
execution(* com.aptech.jb.epet.dao.hibimpl.*.*(..))
这样写应该就可以了
这是com.aptech.jb.epet.dao.hibimpl 包下所有的类的所有方法。。
第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法
最后一个..代表所有的参数。


你可能感兴趣的:(Spring AOP中pointcut expression表达式解析 及匹配多个条件)