Defines a JavaBean (final enhancement) that contains an enhanced method

Source: Internet
Author: User

Using schema

1.AroundLogger class

1 //define a JavaBean that contains an enhancement method2  Public classaroundlogger{3     //wrapping Enhancement processing for annotation mode4     Private Static FinalLogger log = Logger.getlogger (Aroundlogger.class);5      PublicObject Aroundlogger (proceedingjoinpoint JP) { ("A Calls" +jp.gettarget () + "+jp.getsignature (). GetName () +" method, the method parameter is: "7+arrays.tostring (Jp.getargs ()));8         Try {9Object result = Jp.proceed ();//call the target method to get the return value of the target ("A Calls" +jp.gettarget () + "+jp.getsignature (). GetName () +" method, the method return value is: " One+result); A             returnresult; -}Catch(Exception e) { -Log.error (Jp.getsignature (). GetName () + "method throws Exception" +e); the e.printstacktrace (); -}Catch(Throwable e) { -             //TODO auto-generated Catch block - e.printstacktrace (); +         } -         return NULL; +     } A}

2.spring configuration file

1<bean id= "DAO"class= "Com.dao.impl.IUserDaoImpl" ></bean>2<bean id= "Biz"class= "" >3<property name= "DAO" ref= "DAO" ></property>4</bean>5<!--declaring an enhancement method in the same class-6<bean id= "Thelogger"class= "Com.aop.AroundLogger" ></bean>7<!--configuring Facets--8<aop:config>9<!--defining Pointcuts--Ten<aop:pointcut expression= "Execution (** (..))" id= "Pointcut"/> One<!--introduced with enhanced beans-- A<aop:aspect ref= "Thelogger" > -<!--define the Aroundlogger method as a final enhancement and introduce a pointcut-- -<aop:around method= "Aroundlogger" pointcut-ref= "Pointcut"/> the</aop:aspect> -</aop:config>

3. Test similar using schema to configure facets

4. Test results

Defines a JavaBean (final enhancement) that contains an enhanced 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: 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.