The configuration of Spring AOP can be based on annotations or XML files. The previous few are the ways to use annotations. The following describes how to configure using XML files
The test class and the slice class used are similar. Only annotations that belong to AOP need to be removed. The following is an XML configuration for AOP:
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "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 Ten <!--Configuration Bean - One <BeanID= "Arithmeticcalculator"class= "Com.yl.spring.aop.xml.ArithmeticCalculatorImpl"></Bean> A - - <!--Bean that configures facets - the <BeanID= "Loggingaspect"class= "Com.yl.spring.aop.xml.LoggingAspect"></Bean> - - <BeanID= "Validationaspect"class= "Com.yl.spring.aop.xml.ValidationAspect"></Bean> - + <!--Configuring AOP - - <Aop:config> + <!--To Configure a pointcut expression - A <Aop:pointcutexpression= "Execution (public int com.yl.spring.aop.xml.arithmeticcalculator.* (..))"ID= "Pointcut"/> at <!--Configure facets and notifications - - <Aop:aspectref= "Loggingaspect"Order= "2"> - <Aop:beforeMethod= "Beforemethod"Pointcut-ref= "Pointcut"/> - <Aop:afterMethod= "Aftermethod"Pointcut-ref= "Pointcut"/> - <aop:after-throwingMethod= "Afterthrowing"Pointcut-ref= "Pointcut"throwing= "E"/> - <aop:after-returningMethod= "Afterreturning"Pointcut-ref= "Pointcut"returning= "Result"/> in - <Aop:aroundMethod= "Aroundmethod"Pointcut-ref= "Pointcut"/> to </Aop:aspect> + - <Aop:aspectref= "Validationaspect"Order= "1"> the <Aop:beforeMethod= "Vlidateargs"Pointcut-ref= "Pointcut"/> * </Aop:aspect> $ </Aop:config>Panax Notoginseng - </Beans>
Spring aop--XML file-based configuration