expressions and notification types for 7.Spring pointcuts

Source: Internet
Author: User

1. Expressions for Pointcuts

Expression format:

Execution ([modifier] Returns a value type package name. Class Name. Method name (parameter))

Other substitutions:

<!--fully Specify a method -<!--<aop:before method= "log" pointcut= "Execution (public void Com.spring.demo1.UserServiceImpl.save ())"/>  -        <!--modifier can not be written, not necessarily appear -<!--<aop:before method= "log" pointcut= "Execution (void Com.spring.demo1.UserServiceImpl.save ())"/> -<!--The return value type must be written and can be replaced with "*" -<!--<aop:before method= "log" pointcut= "Execution (* Com.spring.demo1.UserServiceImpl.save ())"/> -<!--the package name must be written and can be replaced with "*" -<!--<aop:before method= "log" pointcut= "Execution (* *.spring.demo1.userserviceimpl.save ())"/> -<!--any package structure, "*.. * " -<!--<aop:before method= "log" pointcut= "Execution (* *). *. Userserviceimpl.save ()) "/> -<!--class must be written, can be replaced with "*" -<!--<aop:before method= "log" pointcut= "Execution (* *). *.*serviceimpl.save ()) "/> -<!--method must be written, can be replaced with "*" -<!--<aop:before method= "log" pointcut= "Execution (* *). *.*serviceimpl.save* ()) "/> -<!--parameters must be written, "*" represents a parameter, ". "represents any parameter- 
<!--<aop:before method= "log" pointcut= "Execution (* *). *.*serviceimpl.save* (..)) " /> --

2.AOP Notification Type

1. Front-facing notification
* Executed before the method of the target class executes.
* Configuration file information:

<method= "before"  pointcut-ref= "MYPOINTCUT3"/ >

* Application: Can be used to verify the parameters of the method
2. Final Notice
* After the method of the target class executes, the final notification is executed if the program has an exception.
* Write the specific configuration in the configuration file:

<method= "after"  pointcut-ref= "MYPOINTCUT3"/ >

< Span style= "COLOR: #008000" >         *   Applications: such as freeing resources
    3. Post notification
        *  method. &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP
         *  write a specific configuration in the configuration file:

 <  aop:after-returning  method  = "afterreturning"   Pointcut-ref  = "MyPointcut2"  />  

< Span style= "COLOR: #008000" > < Span style= "COLOR: #808080" >          *  Application: You can modify the return value of a method
    4. Exception throw notification
        *  notification after an exception is thrown
Span style= "COLOR: #808080" >        *  write a specific configuration in the configuration file:

 <  aop:after-throwing  method  = "afterthorwing"   Pointcut-ref  = "MyPointcut3"  />  

< Span style= "COLOR: #808080" > < Span style= "COLOR: #808080" >          *  Application: Packaging exception information
    5. Surround notification
        *  method.
        *  write a specific configuration in the configuration file:

 <  aop:around  method  = "Around"   Pointcut-ref  = "MyPointcut2"  />  

< Span style= "COLOR: #008000" > < Span style= "COLOR: #808080" > < Span style= "COLOR: #808080" >          *  Note: The target method is not executed by default and requires the Proceedingjoinpoint pair to be used for the target object's method execution.

     Public void Around (proceedingjoinpoint joinpoint) {        System.out.println ("Surround notification 1 ...");         Try {            //  manually allow the target object's method to execute             joinpoint.proceed ()        ; Catch (Throwable e) {            e.printstacktrace ();        }        System.out.println ("Surround notification 2 ...");    

How to Pass the attribute in the notification to the Pointcut ?????

How to Pass the attribute in pointcut to the notification ?????

expressions and notification types for 7.Spring 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.