使用注解方式配置 AOP 的基本步骤(复习)
来源:互联网 发布:人工智能的就业前景 编辑:程序博客网 时间:2024/06/05 20:36
Spring AOP 这部分知识比较重要,所以在这里写一个复习的笔记。
使用注解方式配置 AOP 的基本步骤:
1、加入 jar 包
com.springsource.net.sf.cglib-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
spring-aspects-4.0.0.RELEASE.jar
2、在 Spring 的配置文件中加入 aop 的命名空间;
说明:这一步可以通过 Spring Tool Suite 插件自动引入。
3、基于注解的方式来使用 AOP
(1)在配置文件中配置自动扫描的包:
<context:component-scan base-package="com.atguigu.spring.aop"></context:component-scan>
(2)加入使 AspjectJ 注解起作用的配置:
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
为匹配的类自动生成动态代理对象。
4、编写切面类:
(1)写一个一般的 Java 类;
(2)在其中添加要额外实现的功能。
5、配置切面
(1)切面必须是 IOC 中的 bean:添加了 @Component 注解;
(2)声明是一个切面:添加 @Aspect;
通过添加 @Aspect 注解声明这个 bean 是一个切面(即是一个具有特殊功能的 bean)。
(3)声明通知:即额外加入功能对应的方法。
前置通知:
@Before("execution(public int com.atguigu.spring.aop.ArithmeticCalculator.*(int, int))")
其中:@Before 表示在目标方法执行之前执行 @Before 标记的方法的方法体。
@Before 里面的是切入点表达式。
6、在通知中访问连接细节:可以在通知方法中添加 JoinPoint 类型的参数,从中可以访问到方法的签名和方法的参数。
7、@After 表示后置通知:在方法执行之后执行的代码。
参考资料:
Spring AOP–返回通知,异常通知和环绕通知 - _freedom_yl - 博客园
http://www.cnblogs.com/dreamfree/p/4102619.html?utm_source=tuicool
- 使用注解方式配置 AOP 的基本步骤(复习)
- 注解方式使用spring aop的步骤
- spring aop的使用(注解方式以及基于xml配置方式)
- spring aop的使用(注解方式以及基于xml配置方式)
- spring中aop的注解配置方式
- Spring-注解的方式配置AOP-案例
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- Spring使用注解的方式实现AOP
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- Spring_6_使用注解的方式实现AOP
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- 枚举 hdu5311 Hidden String
- 伊豆中文离线地图App上线
- hdu 2489 Minimal Ratio Tree
- TFTP的配置与使用
- CITIC perlite Insulation Building Material Factory
- 使用注解方式配置 AOP 的基本步骤(复习)
- 三极管的电路运用
- 海上钢琴师
- ArcGIS中数据之间的转换接口IFeatureDataConverter2
- 富山中文离线地图App上线
- Linux检测TCP连接断开的一种简单实现方法http://blog.csdn.net/wtewrw/article/details/6547380
- Linear Regression Logistic Regression
- 与基类对象和派生类对象相关的赋值兼容问题
- 并查集树数据结构hdu1325