Spring entry Blog [8. Spring Aop weaving entry point syntax and related case summary]

Source: Internet
Author: User

Aspectj weaving point Syntax:

1. execution (public ** (..) any method of any return value of any class

2. execution (* set * (..) method starting with set of any class

3. execution (* com. xyz. service. AccountService. * (..) specifies the methods in the class for any returned values

4. If execution (* com. xyz. service... *. * (...) returns any value, specify any class or method of the package


Advise summary. Example:


1. Example: directly specify the location and logic to be woven

[Java]
// Specify the weaving method.
@ Before ("execution (public * com. spring. service ..*.*(..))")
Public void BeforeMethod (){
System. out. println ("method start! ");
}


@ AfterReturning ("execution (public * com. spring. service ..*.*(..))")
Public void AfterMethod (){
System. out. println ("After returnning ");
}

2. Specify by defining pointcut:

[Java]
// Define the pointcut woven vertex set
@ Pointcut ("execution (public * com. spring. service ..*.*(..))")
Public void MyMethod (){}

@ Before ("MyMethod ()")
Public void BeforeMethod (){
System. out. println ("method start! ");
}

@ AfterReturning ("MyMethod ()")
Public void AfterMethod (){
System. out. println ("After returnning ");
}

// Intercept before and after execution. Separated by the pjp. proceed Method
@ Around ("MyMethod ()")
Public void aroundProcced (ProceedingJoinPoint pjp) throws Throwable {
System. out. println ("und start ");
Pjp. proceed ();
System. out. println ("und end ");
}

Output result:

Method start!
Und und start
Helloworld
After returnning
Around end

 

Author: zhang6622056

Related Article

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.