Spring4笔记----用基于 XML 的AOP配
来源:互联网 发布:怎么下载苹果软件 编辑:程序博客网 时间:2024/05/16 00:52
(1)声明切面
当使用 XML 声明切面时,需要在 <beans>根元素中导入 aop Schema
在 Bean 配置文件中,所有的 Spring AOP配置都必须定义在 <aop:config>元素内部.对于每个切面而言,都要创建一个 <aop:aspect>元素来为具体的切面实现引用后端 Bean实例.
切面 Bean 必须有一个标示符,供 <aop:aspect>元素引用
(2)声明切入点
切入点使用 <aop:pointcut> 元素声明
切入点必须定义在 <aop:aspect> 元素下,或者直接定义在 <aop:config>元素下.
定义在 <aop:aspect> 元素下:只对当前切面有效
定义在 <aop:config> 元素下:对所有切面都有效
基于 XML 的AOP 配置不允许在切入点表达式中用名称引用其他切入点.
(3)声明通知
通知元素需要使用 <pointcut-ref> 来引用切入点,或用 <pointcut>直接嵌入切入点表达式. method属性指定切面类中通知方法的名称.
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><!--第一步 配置bean----><!-- 配置 bean 将该类纳入到IOC容器中 相当于注解的@Component--><bean id="arithmeticCalculator" class="com.spring.aop.xml.ArithmeticCalculatorImpl"></bean><!-- 配置切面的 bean. --><bean id="loggingAspect"class="com.spring.aop.xml.LoggingAspect"></bean><!-- 配置 AOP --><aop:config><!-- 配置切点表达式 --><aop:pointcut expression="execution(* com.spring.aop.xml.ArithmeticCalculator.*(int, int))" id="pointcut"/><!-- 配置切面及通知 和注解的@Aspect @Before等作用一致 --><aop:aspect ref="loggingAspect" order="1"><aop:before method="beforeMethod" pointcut-ref="pointcut"/><aop:after method="afterMethod" pointcut-ref="pointcut"/><aop:after-throwing method="afterThrowing" pointcut-ref="pointcut" throwing="e"/><aop:after-returning method="afterReturning" pointcut-ref="pointcut" returning="result"/><!-- <aop:around method="aroundMethod" pointcut-ref="pointcut"/>--></aop:aspect></aop:config></beans>
0 0
- Spring4笔记----用基于 XML 的AOP配
- Spring4.0学习笔记009——AOP的配置(基于XML文件)
- Spring4学习笔记-AOP(基于注解的方式)
- Spring4学习笔记-AOP(基于配置文件的方式)
- 基于 xml 来配置 AOP -佟刚老师《Spring4视频教程》学习笔记(22)
- Spring4.0学习笔记008——AOP的配置(基于注解)
- Spring4学习笔记-AOP
- Spring4笔记----AOP概述
- Spring4笔记--AOP
- spring学习笔记 -- day08 基于XML的Spring中的AOP
- Spring4学习:基于@AspectJ和Schema的AOP
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean(供自己学习)
- Spring4.0学习笔记003——Bean的配置一(基于XML文件)
- Spring4.0学习笔记004——Bean的配置二(基于XML文件)
- Spring4.0学习笔记005——Bean的配置三(基于XML文件)
- Spring4.0学习笔记--AOP
- Spring4.0学习笔记-AOP
- 8天学通MongoDB——第八天 驱动实践
- Linux IPC之工具综述
- hdu 5776 sum
- [leetcode] 338. Counting Bits
- swift3.0 中如何在主线程中刷新UI
- Spring4笔记----用基于 XML 的AOP配
- RTMPC Hybrid Engine SDK
- 【日常收获3】
- 【Android 官方文档】翻译Android官方文档 Processes and Threads(五)
- 3.pa小学
- display的block和inline属性
- 华为OJ 中级:汽水瓶
- opencv函数 cvContourArea 计算轮廓面积
- linux关于后台的操作