Spring (AOP with XML method)

Source: Internet
Author: User
Tags aop

Method 1:
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5. XSD Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring -context-2.5.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/s Pring-aop-2.5.xsd "Default-autowire= "ByName" > <Context:annotation-config/> <Context:component-scanBase-package= "Com.daoan"/> <BeanID= "Logintercetor"class= "Com.daoan.aop.LogIntercetor"></Bean> <Aop:config> <!--Pointcut, which methods are added to the plane logic - <Aop:pointcutexpression= "Execution (public * com.daoan.service). *.add (..)) "ID= "Servicepointcut"/> <!--The tangent object referenced by the slice object that joins the declaration is Loginterceptor - <Aop:aspectID= "Logaspect"ref= "Loginterceptor" > <!--before the Add method executes, the before () method under Logintercetor is executed first - <Aop:beforeMethod= "Before"Pointcut-ref= "Servicepointcut" /> </Aop:aspect> </Aop:config></Beans>

 package com.daoan.aop;import org.aspectj.lang.proceedingjoinpoint;import Org.aspectj.lang.annotation.afterreturning;import Org.aspectj.lang.annotation.afterthrowing;import Org.aspectj.lang.annotation.around;import Org.aspectj.lang.annotation.aspect;import Org.aspectj.lang.annotation.before;import Org.aspectj.lang.annotation.pointcut;import org.springframework.stereotype.component;//@Aspect//@Componentpublic class Logintercetor {//(execute the Before () method before the method executes) , if the logic needs to be woven into a method of a class, that object must be spring-managed)//@Before ("Execution (public * com.daoan.service).    *.add (..)) ")    public void before () {System.out.println ("method before"); }//@Around ("Execution (public * com.daoan.service) after the normal operation of the method is complete.    *.add (..)) ")        public void Aroundmethod (Proceedingjoinpoint pjp) throws Throwable {System.out.println ("method around Start");        Pjp.proceed ();    System.out.println ("Method around End"); }}

Method 2:

    <Context:annotation-config/>    <Context:component-scanBase-package= "Com.daoan"/>        <BeanID= "Logintercetor"class= "Com.daoan.aop.LogIntercetor"></Bean>        <Aop:config>        <!--The tangent object referenced by the slice object that joins the declaration is Loginterceptor -        <Aop:aspectID= "Logaspect"ref= "Loginterceptor" >        <!--before the Add method executes, the before () method under Logintercetor is executed first -            <Aop:beforeMethod= "Before"pointcut= "Execution (public * com.daoan.service). *.add (..)) " />        </Aop:aspect>        </Aop:config>

Spring (AOP with XML method)

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.