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. 【Leetcode_easy】997. Find the Town Judge

    problem 997. Find the Town Judge solution: class Solution { public: int findJudge(int N, vector<v ...

  2. Python 的包管理工具 distribute, setuptools, easy_install命令与 pip命令

    Setuptools 是 Python Enterprise Application Kit (PEAK)的一个副项目,它是 Python 的disutils工具的增强工具,可以让程序员更方便地创建和 ...

  3. 基于libuv的TCP设计(二)

    一.本人设想的TCP服务器有如下特性: 1.启动服务,一直监听端口. 2.有新连接(客户端)就通知用户.并把连接接收到的数据回调给用户. 3.客户端连接上后用户可在任意时间发送数据给它. 4.客户端断 ...

  4. 安卓app和苹果app共用一个二维码

    应项目要求,现在安卓app和苹果app共用一个二维码,对外提供下载: <html> <head> <meta http-equiv="Content-Type& ...

  5. 用Python打开文件夹

    用Python读取文件夹, 然后打开文件 下面读取到文件的每一个内容, 然后加上路径 import os path = r'../Downloads/text/content' for filenam ...

  6. LeetCode 637. 二叉树的层平均值(Average of Levels in Binary Tree)

    637. 二叉树的层平均值 637. Average of Levels in Binary Tree LeetCode637. Average of Levels in Binary Tree 题目 ...

  7. Spring MVC <mvc:annotation-driven/>的作用

    一.mvc:annotation-driven的作用 Spring 3.0.x中使用了mvc:annotation-driven后,默认会帮我们注册默认处理请求,参数和返回值的类,其中最主要的两个类: ...

  8. java面向函数编程简单应用

    import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.functio ...

  9. 了解CAdoSqlserver

    include <vector> 表示引用了vector类, vector是STL中的一种数据结构,或者叫容器,功能相当于数组,但是功能强大很多.vector在C++标准模板库中的部分内容 ...

  10. python 并发的开端

    目录 网络并发 进程的基础 2.操作系统 操作系统的发展史 多道技术 第二代 1955~1965 磁带存储--批处理系统 第三代集成电路,多道程序系统(1955~1965) 进程的理论(重点) 2.操 ...