Spring AOP automatic proxy annotation Configuration II

Source: Internet
Author: User

Tag: Port class New return value Npoi location type void top

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd Http://www.spri NGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd ">                 <Context:component-scanBase-package= "Com.zr.utils"></Context:component-scan>                <!--<aop:aspectj-autoproxy ></aop:aspectj-autoproxy> -        <Aop:aspectj-autoproxyProxy-target-class= "true"></Aop:aspectj-autoproxy></Beans>
 Package com.zr.utils; Import org.springframework.stereotype.Component; @Component ("comp")  Public class Implements compute{        publicint div (int num1,int  num2) {        SYSTEM.OUT.PRINTLN ("Division");         return num1/num2;    }}
 Packagecom.zr.utils;Importjava.util.Arrays;ImportOrg.aspectj.lang.JoinPoint;ImportOrg.aspectj.lang.annotation.After;Importorg.aspectj.lang.annotation.AfterReturning;Importorg.aspectj.lang.annotation.AfterThrowing;ImportOrg.aspectj.lang.annotation.Aspect;ImportOrg.aspectj.lang.annotation.Before;ImportOrg.aspectj.lang.annotation.Pointcut;Importorg.springframework.stereotype.Component, @Aspect @component ("Testaspect") Public classtestaspect {@Pointcut ("Execution (* com.zr.utils.calculate.* (..))")    Private voidtestpointcut () {}//The first * represents an arbitrary modifier and any return value, where: matches any number of arguments .@Before ("Testpointcut ()")     Public voidMethodbefore (Joinpoint joinpoint) {System.out.println ("Execution method:" +joinpoint.getsignature (). GetName () + "before" + "parameter:" +arrays.aslist (Joinpoint.getargs ())); }    //The first * represents any return value under the public modifier, the first * represents any method under the Com.zr.utils.Calculate path@After (value= "Testpointcut ()")     Public voidMethodafter (Joinpoint joinpoint) {System.out.println ("Execution method:" +joinpoint.getsignature (). GetName () + "after"); }        //match the first parameter to a method of type int: matches any number of arguments of any type@AfterReturning (pointcut= "testpointcut ()", returning= "result")     Public voidmethodafterrunning (joinpoint joinpoint,object result) {System.out.println ("+" is returned after the result: "+result); }    //A method that matches a parameter of type int, int.@AfterThrowing (pointcut= "testpointcut ()", throwing= "Exception")     Public voidmethodafterthrowing (joinpoint joinpoint,exception Exception) {System.out.println ("Exception notification, after the method throws an exception, execute" + ", Exception Log:" +exception); }}
 Packagecom.zr.utils;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classTESTAOP { Public Static voidMain (string[] args) {applicationcontext CTC=NewClasspathxmlapplicationcontext ("Context.xml"); /*Calculate Calculate = (Calculate) ctc.getbean ("comp");*/Calculate C= (Calculate) ctc.getbean ("comp"); intresult = C.div (10, 2); }}

Spring AOP automatic proxy annotation Configuration II

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.