19SPRING_AOP Programming (AspectJ) _ using @pointcut annotations to define Pointcuts

Source: Internet
Author: User

Our previous approach was to use

@AfterReturning (value= "Execution (* com.guigu.shen.anotion.userdaoimpl.* (..))", returning= "ReturnVal")  Public void afterreturning (joinpoint joinpoint,object returnval) {System.out.println ("This is Afterreturning method"); System.out.println (returnval);    }

Such a way. In this way, the tangency point and the notice are closely linked, and we change the other way. Use @pointcut annotations to define pointcuts. Untie the two.

The cases are as follows:

The second step defines a notification, using the tangent point
What is written here is the definition of the method that is modified with @pointcut annotations.
@After ("MyPoint ()")publicvoid after () { System.out.print ("final notification, freeing resources" );}
First step: Define a pointcut @pointcut ("Execution (* com.guigu.shen.anotion.userdaoimpl.* (..))" )
Must be private void no parameter privatevoid mypoint () { }

The effect is exactly the same as before.

Extension: Is there any more I want to intercept a pointcut? I already have a tangent point above, so can a advice have multiple pointcuts. The answer is: Of course you can.

In the development of such a requirement, that is, to cut the DAO layer, but also to cut the server over there.

19SPRING_AOP Programming (AspectJ) _ using @pointcut annotations to define Pointcuts

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.