Parsing of pointcut expression expressions in Spring AOP

Source: Internet
Author: User

Pointcut refers to those methods that need to be executed "AOP", which is described by "Pointcut Expression".
Pointcut can be defined in the following ways or by && | | and! The way to combine.
Args ()
@args ()
Execution ()
This ()
Target ()
@target ()
Within ()
@within ()
Where execution is the most used, the format is:
Execution (Modifiers-pattern ret-type-pattern declaring-type-pattern? Name-pattern (Param-pattern) Throws-pattern?)
Returning type Pattern,name pattern, and parameters pattern is required.
Ret-type-pattern: can represent any return value, the class name of the full path, and so on.
Name-pattern: Specifies the method name, * represents so, set*, which represents all methods that begin with set.
Parameters Pattern: Specifies the method parameter (the declared type), (..) Represents all parameters, (*) represents a parameter, (*,string) represents the first parameter as any value, and the second is a String type.
To illustrate:
Execution of any public method:
Execution (Public * * (..))
Any execution of a method that begins with "set":
Execution (* set* (..))
Execution of any method of the Accountservice interface:
Execution (** (..))
The execution of any method defined in the service package:
Execution (**.* (..))
The execution of any method that defines any class in the service package and all child packages:
Execution (* *.*(..))
The execution of any method that defines the JoinPointObjP2 class in the Pointcutexp package and all the child packages:
Execution (* com.test.spring.aop.pointcutexp). joinpointobjp2.* (..)) ")
> Closest to (..) For the method name, near. * (..)) is the class name or interface name, as in the example above joinpointobjp2.* (..))

Any class in the Pointcutexp package.
Within (com.test.spring.aop.pointcutexp.*)
Any class in the Pointcutexp package and all child packages.
Within (com.test.spring.aop.pointcutexp. *)
All classes that implement the Intf interface, if INTF is not an interface, are qualified intf a single class.
This (com.test.spring.aop.pointcutexp.Intf)
> When a class that implements an interface is AOP, the Getbean method must be cast as the interface type, not the type of the class.

Any method of all classes with @transactional callouts.
@within (org.springframework.transaction.annotation.Transactional)
@target (org.springframework.transaction.annotation.Transactional)
Any method with a @transactional callout.
@annotation (org.springframework.transaction.annotation.Transactional)
> @within and @target Annotations for classes, @annotation are annotations to methods

The parameter has a method with the @transactional callout.
@args (org.springframework.transaction.annotation.Transactional)
The parameter is a method of type string (run is a decision).
Args (String)
The Pointcut can be configured in Java annotations and XML two ways, as follows:

1 <Aop:config>2     <Aop:aspectref= "Aspectdef">3         <Aop:pointcutid= "POINTCUT1"expression= "Execution (* com.test.spring.aop.pointcutexp). joinpointobjp2.* (..)) "/>4         <Aop:beforePointcut-ref= "POINTCUT1"Method= "Beforeadvice" />5     </Aop:aspect>6 </Aop:config>7 8 @Component9 @AspectTen Public class Aspectdef { One //@Pointcut ("Execution (* com.test.spring.aop.pointcutexp). joinpointobjp2.* (..)) ") A //@Pointcut ("Within (com.test.spring.aop.pointcutexp. *)") - //@Pointcut ("This (com.test.spring.aop.pointcutexp.Intf)") - //@Pointcut ("Target (com.test.spring.aop.pointcutexp.Intf)") the //@Pointcut ("@within (org.springframework.transaction.annotation.Transactional)") - //@Pointcut ("@annotation (org.springframework.transaction.annotation.Transactional)") - @Pointcut ("args (String)") - Public void Pointcut1 () { +     } - @Before (value = "pointcut1 ()") + Public void Beforeadvice () { A System.out.println ("pointcut1 @Before ..."); at}

Parsing of pointcut expression expressions in Spring AOP

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.