Spring aop--XML file-based configuration

Source: Internet
Author: User

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

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: info-contact@alibabacloud.com 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.