8.切入点表达式

  现在我们介绍一下最重要的切入点表达式:

  如上文所说,定义切入点时需要一个包含名字和任意参数的签名,还有一个切入点表达式,就是* findById*(..)这一部分。

  切入点表达式的格式:execution([可见性] 返回类型 [声明类型].方法名(参数) [异常])

  其中【】中的为可选,其他的还支持通配符的使用:

    *:匹配所有字符
      ..:一般用于匹配多个包,多个参数
      +:表示类及其子类

  运算符有:&&、||、!

  

切入点表达式关键词:

    1)execution:用于匹配子表达式。

//匹配com.cjm.model包及其子包中所有类中的所有方法,返回类型任意,方法参数任意
            @Pointcut("execution(* com.cjm.model..*.*(..))")
            public void before(){}

2)within:用于匹配连接点所在的Java类或者包。

//匹配Person类中的所有方法
            @Pointcut("within(com.cjm.model.Person)")
            public void before(){}

//匹配com.cjm包及其子包中所有类中的所有方法

@Pointcut("within(com.cjm..*)")
            public void before(){}

3) this:用于向通知方法中传入代理对象的引用。
            @Before("before() && this(proxy)")
            public void beforeAdvide(JoinPoint point, Object proxy){
                  //处理逻辑
            }

4)target:用于向通知方法中传入目标对象的引用。
            @Before("before() && target(target)
            public void beforeAdvide(JoinPoint point, Object proxy){
                  //处理逻辑
            }

5)args:用于将参数传入到通知方法中。
            @Before("before() && args(age,username)")
            public void beforeAdvide(JoinPoint point, int age, String username){
                  //处理逻辑
            }
 
      6)@within :用于匹配在类一级使用了参数确定的注解的类,其所有方法都将被匹配。

@Pointcut("@within(com.cjm.annotation.AdviceAnnotation)") - 所有被@AdviceAnnotation标注的类都将匹配
            public void before(){}

  

7)@target :和@within的功能类似,但必须要指定注解接口的保留策略为RUNTIME。
            @Pointcut("@target(com.cjm.annotation.AdviceAnnotation)")
            public void before(){}

8)@args :传入连接点的对象对应的Java类必须被@args指定的Annotation注解标注。
            @Before("@args(com.cjm.annotation.AdviceAnnotation)")
            public void beforeAdvide(JoinPoint point){
                  //处理逻辑
            }

  

9)@annotation :匹配连接点被它参数指定的Annotation注解的方法。也就是说,所有被指定注解标注的方法都将匹配。
            @Pointcut("@annotation(com.cjm.annotation.AdviceAnnotation)")
            public void before(){}

10)bean:通过受管Bean的名字来限定连接点所在的Bean。该关键词是Spring2.5新增的。
            @Pointcut("bean(person)")
            public void before(){}

最新文章

  1. 【svn】SSL error: A TLS warning alert has been received的解决方法
  2. Ref 与 Out 的使用方法及区别
  3. Last time, I wrote a pager, but now it seems this no longer has use, so I want to paste it here.
  4. 奶牛健美操(codevs 3279)
  5. 【转】Web性能压力测试工具之ApacheBench(ab)详解
  6. ABAP - 3D Graphs with SAP
  7. (31)odoo中的时间
  8. 使用eclipse创建java程序可执行jar包
  9. ansible检测链路状态和切换状态
  10. Asp.Net MVC--Controller激活2
  11. 进程创建函数fork()、vfork() ,以及excel()函数
  12. samba搭建
  13. js判断数组和对象
  14. 【Demo 0011】多媒体播放器
  15. HorizontalScrollView做页卡的一个小记录
  16. MPSOC之3——centos环境配置及petalinux安装及使用
  17. Java并发系列[5]----ReentrantLock源码分析
  18. linux svn代码回滚命令
  19. linux终端自定义设置
  20. 网络基础 Windows telnet使用简介及相关问题解决方案

热门文章

  1. C# Request 获取Url
  2. 哪个中年IT男不是一边面对危机,一边咬牙硬抗
  3. 彻底放弃没落的MFC,对新人的忠告! by FreeWick
  4. Go语言之高级篇beego框架之model设计构造查询
  5. VMWare虚拟机中CPU过高的问题
  6. npm install node-sass失败
  7. 关于select标签曾经踩过的几个坑!
  8. 【PMP】项目和运营的区别
  9. GDAL对TIF创建内建金字塔一个问题
  10. android 制作9.png图