Spring AOP--基于XML文件的配置

Spring AOP的配置可以基于注解,也可以基于XML文件。前面几篇都是使用注解的方式。下面介绍下使用XML文件如何配置

使用的测试类和切面类都类似。只需要属于AOP的注解去掉即可。下面是AOP的XML配置:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:aop="http://www.springframework.org/schema/aop"
 5     xmlns:context="http://www.springframework.org/schema/context"
 6     xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
 7         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 8         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
 9     
10     <!-- 配置bean -->
11     <bean id="arithmeticCalculator" class="com.yl.spring.aop.xml.ArithmeticCalculatorImpl"></bean>
12     
13     
14     <!-- 配置切面的bean -->
15     <bean id="loggingAspect" class="com.yl.spring.aop.xml.LoggingAspect"></bean>
16     
17     <bean id="validationAspect" class="com.yl.spring.aop.xml.ValidationAspect"></bean>
18     
19     <!-- 配置AOP -->
20     <aop:config>
21         <!-- 配置切点表达式 -->
22         <aop:pointcut expression="execution(public int com.yl.spring.aop.xml.ArithmeticCalculator.*(..))" id="pointcut"/>
23         <!-- 配置切面及通知 -->
24         <aop:aspect ref="loggingAspect" order="2">
25             <aop:before method="beforeMethod" pointcut-ref="pointcut"/>
26             <aop:after method="afterMethod" pointcut-ref="pointcut"/>
27             <aop:after-throwing method="afterThrowing" pointcut-ref="pointcut" throwing="e"/>
28             <aop:after-returning method="afterReturning" pointcut-ref="pointcut" returning="result"/>
29             
30             <aop:around method="aroundMethod" pointcut-ref="pointcut"/>
31         </aop:aspect>
32         
33         <aop:aspect ref="validationAspect" order="1">
34             <aop:before method="vlidateArgs" pointcut-ref="pointcut"/>
35         </aop:aspect>
36     </aop:config>
37     
38 </beans>

 

转载于:https://www.cnblogs.com/dreamfree/p/4102680.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值