Spring AOP AspectJ Pointcut Expression Example

Source: Internet
Author: User

Main Source: http://howtodoinjava.com/spring/spring-aop/writing-spring-aop-aspectj-pointcut-expressions-with-examples/

1. Method Label Matching mode

Assume that the interface Employeemanager interface is defined.

1)

Execution (* com.howtodoinjava.employeemanager.* (..))

The above pointcut expression can match all the methods in the Employeemanger interface.

2)

When the tangent method and the Employeemanager interface are within the same package, if the pointcut expression matches all of the methods, the expression can be changed to:

Execution (* employeemanager.* (..))

3) All public methods that match the Employeemanager interface.

Execution (Public * employeemanager.* (..))

4) match the permissions in the Employeemanager interface to public and return all methods of type Employeedto.

Execution (public employeedto employeemanager.* (..))

5) All methods that match the permissions in the Employeemanager interface to public and return a type of employeedto, and the first parameter is the Employeedto type.

execution(publicEmployeeDTO EmployeeManager.*(EmployeeDTO, ..))

6) All methods that match the permissions in the Employeemanager interface to public, the return type is Employeedto, and the parameters are explicitly defined as Employeedto,integer.

Execution (Public employeedto employeemanager.* (Employeedto, Integer))

2. Type Label matching mode

1) match all the methods in all types under the Com.howtodoinjava package.

Within (com.howtodoinjava.*)

2) match all the methods in the Com.howtodoinjava package and all types under its sub-package.

Within (Com.howtodoinjava. *)

3) match all the methods under one class for the other package.

Within (Com.howtodoinjava.EmployeeManagerImpl)

4) match all methods under one class under the same package.

Within (Employeemanagerimpl)

5) match all the methods of all inheritors under an interface.

Within (employeemanagerimpl+)

3. Bean Name Matching mode

Matches all methods in the beans ending with the manager.

Bean (*manager)

4. Pointcut Expression Stitching

In AspectJ, pointcut expressions can be spliced by &&,| |,! and other operators.

Bean (*manager) | | Bean (*dao)

This example shows all the methods in the beans that match the end of the manager or end with DAO.

Spring AOP AspectJ Pointcut Expression Example

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.