Spring Aop织入点语法
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织入点语法的更多相关文章
- Spring AOP: 织入的顺序
spring AOP 采用和 AspectJ 一样的优先顺序来织入增强处理:在进入连接点时,高优先级的增强处理将先被织入:在退出连接点时,高优先级的增强处理会后被织入. 当不同的切面里的两个增强处理需 ...
- Spring AOP配置与应用
1. 两种方式: a) 使用Annotation b) 使用xml 2. Annotation a) 加上对应的xsd文件spring-aop.xsd b) ...
- Spring Aop的理解和简单实现
1.AOP概念 所说的面向切面编程其实就是在处理一系列业务逻辑的时候这一系列动作看成一个动作集合.比如连接数据库来说: 加载驱动-----获取class--------获取连接对象-------访问数 ...
- Spring AOP 整理
在 xml中加 xmlns:aop="http://www.springframework.org/schema/aop" http://www.springframework.o ...
- SPRING AOP ....0 can't find referenced pointcut
下载最新的aspectjweaver就可以了,因为JDK的版本的问题不兼容. //织入点语法 @Pointcut("execution(public * com.frank.dao..*.* ...
- Spring Aop之Cglib实现原理详解
Spring Aop实现对目标对象的代理,AOP的两种实现方式:Jdk代理和Cglib代理.这两种代理的区别在于,Jdk代理与目标类都会实现同一个接口,并且在代理类中会调用目标类中被代理的方法,调用者 ...
- Spring Aop基于注解的实现
一.AspectOriented Programing,面向切面编程. AOP主要用于日志记录,性能统计,安全控制(权限控制),事务处理,异常处理等.将日志记录,性能统计,安全控制,事务处理,异常 ...
- Spring AOP全面详解(超级详细)
如果说 IOC 是 Spring 的核心,那么面向切面编程AOP就是 Spring 另外一个最为重要的核心@mikechen AOP的定义 AOP (Aspect Orient Programming ...
- 框架源码系列三:手写Spring AOP(AOP分析、AOP概念学习、切面实现、织入实现)
一.AOP分析 问题1:AOP是什么? Aspect Oriented Programming 面向切面编程,在不改变类的代码的情况下,对类方法进行功能增强. 问题2:我们需要做什么? 在我们的框架中 ...
随机推荐
- jquery img src赋值
不用Jquery时:document.getElementById("imageId").src = "xxxx.jpg"; 用Jquery时:$(" ...
- Linux18.04换源等等等配置
root用户 sudo passwd root 安装Tools 文件→其他位置→Vmware Tools→打开终端. 管理员权限→copy→tar -zxvf 文件名解压→打开vmware-tools ...
- URI和URL的关系与区别
首先给大家举个例子,有一家公司的总经理,某天,给了我一张名片,上面写了他的头衔,北京XXX公司总经理 张三,还有他的办公室地址,北京市海淀区长安街35号北京XXX公司总经理办公室,那么,我以后给我的朋 ...
- Python——raise引发异常
程序出现错误,会自动引发异常,Python也允许使用raise语句自行引发异常. 一.使用raise引发异常 单独一个raise引发异常,默认引发RuntimeError异常,例: try: prin ...
- Markdown试试
from os import time print("haha") from os import time print("haha") time.time()! ...
- java实现HTTP请求 HttpUtil
示例: package com.sensor.utils; import java.net.HttpURLConnection; import java.net.URL; public class H ...
- SqlServer中Index Seek的匹配规则(一)
我们知道在SqlServer中,索引对查询语句的优化起着巨大的作用,一般来说在执行计划中出现了Index Seek的步骤,我们就认为索引命中了.但是Index Seek中有两个部分是值得我们注意的,我 ...
- Informix从一个表更新多选数据到另一个表
功能如题, Informix从一个表更新多选数据到另一个表 例如, 要更新tab01的几个字段数据, 这些数据来自tab02, tab01和tab02之间通过id关联 参考语句: update tab ...
- Access-Control-Max-Age
app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCreden ...
- snort_inline
snort_inline Link http://snort-inline.sourceforge.net/oldhome.html What is snort_inline? snort_inl ...