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