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

Spring Aop织入点语法的更多相关文章

  1. Spring AOP: 织入的顺序

    spring AOP 采用和 AspectJ 一样的优先顺序来织入增强处理:在进入连接点时,高优先级的增强处理将先被织入:在退出连接点时,高优先级的增强处理会后被织入. 当不同的切面里的两个增强处理需 ...

  2. Spring AOP配置与应用

    1.     两种方式: a)     使用Annotation b)     使用xml 2.     Annotation a)     加上对应的xsd文件spring-aop.xsd b)   ...

  3. Spring Aop的理解和简单实现

    1.AOP概念 所说的面向切面编程其实就是在处理一系列业务逻辑的时候这一系列动作看成一个动作集合.比如连接数据库来说: 加载驱动-----获取class--------获取连接对象-------访问数 ...

  4. Spring AOP 整理

    在 xml中加 xmlns:aop="http://www.springframework.org/schema/aop" http://www.springframework.o ...

  5. SPRING AOP ....0 can't find referenced pointcut

    下载最新的aspectjweaver就可以了,因为JDK的版本的问题不兼容. //织入点语法 @Pointcut("execution(public * com.frank.dao..*.* ...

  6. Spring Aop之Cglib实现原理详解

    Spring Aop实现对目标对象的代理,AOP的两种实现方式:Jdk代理和Cglib代理.这两种代理的区别在于,Jdk代理与目标类都会实现同一个接口,并且在代理类中会调用目标类中被代理的方法,调用者 ...

  7. Spring Aop基于注解的实现

    一.AspectOriented Programing,面向切面编程.   AOP主要用于日志记录,性能统计,安全控制(权限控制),事务处理,异常处理等.将日志记录,性能统计,安全控制,事务处理,异常 ...

  8. Spring AOP全面详解(超级详细)

    如果说 IOC 是 Spring 的核心,那么面向切面编程AOP就是 Spring 另外一个最为重要的核心@mikechen AOP的定义 AOP (Aspect Orient Programming ...

  9. 框架源码系列三:手写Spring AOP(AOP分析、AOP概念学习、切面实现、织入实现)

    一.AOP分析 问题1:AOP是什么? Aspect Oriented Programming 面向切面编程,在不改变类的代码的情况下,对类方法进行功能增强. 问题2:我们需要做什么? 在我们的框架中 ...

随机推荐

  1. 把github代码自动部署到服务器

    一.参考文献 https://developer.github.com/webhooks/ https://docs.gitlab.com/ee/user/project/integrations/w ...

  2. solr搜索结果转实体类对象的两种方法

    问题:就是把从solr搜索出来的结果转成我们想要的实体类对象,很常用的情景. 1.使用@Field注解 @Field这个注解放到实体类的属性[字段]中,例如下面 public class User{ ...

  3. IdentityServer4 学习二

    进入identityserver4的官网:https://identityserver.io/ 找到文档 从overview下开始按照官方文档练习: 安装自定义模板 dotnet new -i Ide ...

  4. python基础学习(十一)

    22.类 # 类 class # 实例 实体 instance class Student: # 空语句 保持结构的完整性 pass jack = Student() jack.name = &quo ...

  5. Git使用总结(二):分支管理

    1.创建分支 a.直接创建 git branch dev(分支名) b.基于某个历史版本创建分支 git branch dev HEAD 2.查看分支 git branch -av 3.删除分支 gi ...

  6. BJFU——205基于顺序存储结构的图书信息表的排序

    #include<stdio.h> #include<stdlib.h> #define MAX 1000 typedef struct{ double no; char na ...

  7. 剑指offer22:从上往下打印出二叉树的每个节点,同层节点从左至右打印。

    1 题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 2 思路和方法 使用一个队列存放节点.先将根节点加入到队列中,然后循环遍历队列中的元素,遍历过程中,访问该节点的左右子节点,再将左 ...

  8. WUSTOJ 1333: Sequential game(Java)

    题目链接:1333: Sequential game Description Sequential detector is a very important device in Hardware ex ...

  9. 机器学习-HMM隐马尔可夫模型-笔记

    HMM定义 1)隐马尔科夫模型 (HMM, Hidden Markov Model) 可用标注问题,在语音识别. NLP .生物信息.模式识别等领域被实践证明是有效的算法. 2)HMM 是关于时序的概 ...

  10. pyrhon 第一个小购物车例子

    product_list=[[],[],[],[]] shopping_list=[] salary = input("请输入你的工资:") if salary.isdigit() ...