Spring AOP-configuration based on XML files, aop-xml

Source: Internet
Author: User

Spring AOP-configuration based on XML files, aop-xml

The configuration of Spring AOP can be based on Annotations or XML files. The previous articles use annotations. The following describes how to configure an XML file.

The used test class and cut class are similar. You only need to remove the annotation that belongs to AOP. The XML configuration of AOP is as follows:

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/schem A/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 <! -- Configure bean --> 11 <bean id = "arithmeticCalculator" class = "com. yl. spring. aop. xml. ArithmeticCalculatorImpl"> </bean> 12 13 14 <! -- Configure 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 <! -- Configure AOP --> 20 <aop: config> 21 <! -- Configure the cut expression --> 22 <aop: pointcut expression = "execution (public int com. yl. spring. aop. xml. arithmeticCalculator. *(..)) "id =" pointcut "/> 23 <! -- Configuration aspect and notification --> 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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.