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 @H_404_66@<!--@H_404_66@ 配置bean @H_404_66@--> 11 @H_404_66@bean id="arithmeticCalculator" class="com.yl.spring.aop.xml.ArithmeticCalculatorImpl"></bean12 13 14 @H_404_66@ 配置切面的bean 15 ="loggingAspect"="com.yl.spring.aop.xml.LoggingAspect"16 17 ="validationAspect"="com.yl.spring.aop.xml.ValidationAspect"18 19 @H_404_66@ 配置AOP 20 @H_404_66@aop:config21 @H_404_66@ 配置切点表达式 22 @H_404_66@aop:pointcut expression="execution(public int com.yl.spring.aop.xml.ArithmeticCalculator.*(..))" id="pointcut"/> 23 @H_404_66@ 配置切面及通知 24 @H_404_66@aop:aspect ref@H_404_66@ order="2"25 @H_404_66@aop:before method="beforeMethod" pointcut-ref26 @H_404_66@aop:after ="afterMethod"27 @H_404_66@aop:after-throwing ="afterThrowing"="pointcut" throwing="e"28 @H_404_66@aop:after-returning ="afterReturning" returning="result"29 30 @H_404_66@aop:around ="aroundMethod"31 </aop:aspect32 33 ="1"34 ="vlidateArgs"35 36 37 38 @H_404_66@beans>