Aspectj织入点语法:

1、execution(public * *(..))   任何类的任何返回值的任何方法

2、execution(* set*(..))       任何类的set开头的方法

3、execution(* com.xyz.service.AccountService.*(..))         任何返回值的规定类里面的方法

4、execution(* com.xyz.service..*.*(..))      任何返回值的,规定包或者规定包子包的任何类任何方法

Advise总结。举例说明:

1、举例:直接指定要织入的位置和逻辑

1
2
3
4
5
6
7
8
9
10
11
//指定织入的方法。
    @Before("execution(public * com.spring.service..*.*(..))")
    public void BeforeMethod(){
        System.out.println("method start!");
    }
     
     
    @AfterReturning("execution(public * com.spring.service..*.*(..))")
    public void AfterMethod(){
        System.out.println("After returnning");
    }

2、通过定义pointcut来指定:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//定义pointcut织入点集合
    @Pointcut("execution(public * com.spring.service..*.*(..))")
    public void MyMethod(){}
     
    @Before("MyMethod()")
    public void BeforeMethod(){
        System.out.println("method start!");
    }
     
    @AfterReturning("MyMethod()")
    public void AfterMethod(){
        System.out.println("After returnning");
    }
     
    //执行前后都拦截。以pjp.proceed的方法分割开来
    @Around("MyMethod()")
    public void aroundProcced(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("around start");
        pjp.proceed();
        System.out.println("around end");
    }

输出结果:

method start! 
around start 
helloworld 
After returnning 
around end

最新文章

  1. SQL 表的完整性
  2. egret.Tween、egret.Ease
  3. Trie树的应用:查询IP地址的ISP
  4. Centos6.6上安装mysql5.6中的一些典型问题
  5. 解决SQLite3数据库Error: database disk image is malformed
  6. jquery.unobtrusive-ajax.js的扩展,做到片段式加载
  7. Chopsticks
  8. Android handler.obtainMessage()
  9. https://lua-toolbox.com/
  10. hibernate和mybatis思想,区别,优缺点
  11. android--jenkins+gradle+android自动化构建apk步骤(转)
  12. 解决getElementsByClassName兼容问题
  13. 初探 discuz
  14. Ubuntu16.04下的2009q3交叉编译工具链的搭建
  15. Android精通之OrmLite数据库框架,Picasso框架,Okio框架,OKHttp框架
  16. 【java】之常用四大线程池用法以及ThreadPoolExecutor详解
  17. phpcms首页如加上用户登录的信息?
  18. 解决selenium不支持firefox低版本的问题
  19. CUBA 7 新特性(上篇)
  20. php 性能优化

热门文章

  1. RobotFramework: 获取当前时间戳
  2. WXS----数据类型
  3. Head First Design Patterns HeadFirst 设计模式
  4. yarn 的常用命令
  5. NAT的配置
  6. 使用fiddl模拟弱网
  7. GraphHopper-初识
  8. crontab每小时运行一次
  9. python基础学习(十四)
  10. Java设计模式:23种设计模式(转)