Spring's pointcut (a static pointcut)

Source: Internet
Author: User

Pointcut is the pointcut that configures the cut-in position of the slice. Because the granularity of pointcuts in spring is a method level, the role of pointcut in spring AOP is to configure which of the classes are within the point of our definition and which methods should be filtered out. Spring's pointcut is divided into static pointcut, dynamic pointcut and user-defined pointcut three kinds, in which static pointcut only need to consider class name, method name; dynamic Pointcut In addition, consider the parameters of the method, So that the location of the pointcut can be determined dynamically at run time.

1. Static Pointcut

Static means invariant, such as the names of methods and classes. So we can determine which methods of those classes are based on the signatures of classes and methods within the pointcut we define, and which should be filtered out.

The following implementation classes for the static pointcut in the definition in spring are described below:

1, Namematchmethodpointcut: Only on the method name discriminant static Pointcut implementation class.

Examples of usage are as follows:

Code

<bean id="NameMatchMethodPointcut" class="org.springframework.aop.support.NameMatchMethodPointcut">
   <property name="mappedNames">
     <list>
       <value>pos*</value>
       <value>start</value>
     </list>
  </property>
</bean> 

Note: post* represents all methods that start with a POS. (case sensitive).

In addition, Namematchmethodpointcut exposes the Classfilter attribute of the Classfilter type, which can be used to specify the implementation class of the Classfilter interface to set the class filter. The Classfilter interface is defined as follows:

Code

package org.springframework.aop;

public interface ClassFilter {

  boolean matches(Class clazz);
  ClassFilter TRUE = TrueClassFilter.INSTANCE;
} 
package org.springframework.aop;

Where the matches method is used for the match of the class, the parameter clazz is the target class that needs to match, and returns true if the match succeeds.

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.