Expression asterisk (*) meaning in Spring AOP

Source: Internet
Author: User
[HTML]View plain copy <aop:config> <aop:pointcut id= "method" expression= "Execution (* *). Service.save (..)) " /> </aop:config>


The full type of expression, as follows:
Execution (Modifiers-pattern ret-type-pattern declaring-type-pattern? Name-pattern (Param-pattern) Throws-pattern?)

Modifiers-pattern representative modifier (public/protect, etc.)

Ret-type-pattern represents the return type (Int/string/long, etc.)

Declaring-type-pattern represents the matching path (which is under what package)

Name-pattern represents the matching method name

Throws-pattern exception Match Type
You can not fill in the back with a question mark. is the meaning of 0 or 1 in a regular expression.

The return type mode determines that the return type of the method must match one connection point in turn. The most frequent return type pattern you will use is *, which represents the matching of any return type. A full-qualified type name will only match the method that returns the given type. The name pattern matches the method name. You can use the * wildcard character as all or part of the naming pattern. The parameter pattern is slightly more complex: () matches a method that does not accept any parameters, and (..) matches a method that accepts any number of parameters (0 or more). The pattern (*) matches a method that accepts a parameter of any type. Mode (*,string) matches a method that accepts two parameters, the first of which can be any type, and the second must be of type String. See the Language Semantics section of the ASPECTJ Programming Guide.

Some examples of common pointcut expressions are given below.

Match all methods [HTML] view plain Copy Execution (* * (..)) [HTML] view plain Copy the execution of any public method:

Execution (Public * * (..))

Any execution of a method that begins with "set":

Execution (* set* (..))

Execution of any method of the UserService interface:

Execution (* com.service.userservice.* (..))

The execution of any method defined in the service package:

Execution (* com.service.*.* (..))

The execution of any method defined in a service package or a child package:

Execution (* com.service). *.*(..))

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.