AspectJ entry point syntax supported by Spring AOP

Source: Internet
Author: User

Source: http://jinnianshilongnian.iteye.com/blog/1420691

AspectJ Entry Point Indicators supported by Spring AOP

The entry point indicator is used to indicate the purpose of the entry point expression. Currently, only the execution method is the connection point in Spring AOP. The AspectJ Entry Point Indicator supported by Spring AOP is as follows:

Execution:The connection point used for matching method execution;

Within:Used to match methods of the specified type for execution;

This:Used to match the currentAOPMethod of executing the proxy object type. Note thatAOPProxy object type matching, which may include introduced interface and type matching;

Target:It is used to match the execution method of the current target object type. Note that it is the type matching of the target object, which does not include the introduced interface and type matching;

Args:The parameter used to match the currently executed method is the specified type of execution method;

@:Used to match methods that hold the specified annotation type;

@ Target:It is used to match the execution method of the current target object type, where the target object holds the specified annotation;

@ Args:It is used to match the execution of the specified annotation of the input parameter of the currently executed method;

@ Annotation:It is used to match the method that holds the specified annotation for the current execution method;

Bean:Spring AOPExtended,AspectJThere is no indicator for matching a specific nameBeanObject execution method;

Reference pointcut:Indicates to reference other named start points, only@ ApectJStyle support,SchemaStyle is not supported.

The entry point indicators supported by AspectJ include call, get, set, preinitialization, staticinitialization, initialization, handler, adviceexecution, withincode, cflow, cflowbelow, if, @ this, And @ withincode; however, Spring AOP currently does not support these indicators. Using these indicators will throw an IllegalArgumentException exception. These indicators may be extended in the future by Spring AOP.

Naming and anonymous entry point

The named start point can be referenced by other start points, but the anonymous start point cannot. Only @ AspectJ supports the naming entry point, while the Schema style does not support the naming entry point as follows. @ AspectJ uses the following method to reference the naming entry point:

Type matching syntax

First, let's take a look at the wildcard matching the AspectJ type.

*Matches any number of characters;

..(Two vertices) Repeat matching any number of characters, for example, matching any number of quantum packets in type mode, and matching any number of parameters in method parameter mode.

+Matches the child type of the specified type. It can only be placed behind the type mode as a suffix.

Matching expression type

Matching type: Use the following method to match

Annotation? Class Name

  • Note:(Optional) annotation held on the type, such as @ Deprecated;
  • Class Name:Required. It can be a fully qualified name of any class.

Matching Method execution:Use the following method for matching:

Annotation? Modifier? Return Value Type Declaration? Method Name (parameter list) exception list?

  • Note:Optional. annotation held on the method, for example, @ Deprecated;
  • Modifier:Optional, such as public and protected;
  • Return Value Type:Required. It can be of any type. "*" indicates all types;
  • Type Declaration:Optional. It can be of any type;
  • Method Name:Required. You can use "*" for pattern matching;
  • Parameter List:"()" Indicates that the method does not have any parameters; "(...) "indicates the matching method that accepts any parameter." (..., java. lang. string) "indicates that java is accepted for matching. lang. the String type parameter ends, and the front side of the parameter can accept methods with any parameter; "(java. lang. string ,..) java. lang. start with a String-type parameter, and the following method can accept any parameter; "(*, java. lang. string) "indicates that java is accepted for matching. lang. the String type parameter ends, and the front side accepts a method of any type parameter;
  • Exception list:(Optional) It is declared as "throws exception full qualified Name List". If multiple exception full qualified names are listed, they are separated by ",", such as throws java. lang. illegalArgumentException, java. lang. arrayIndexOutOfBoundsException

Matching BeanName:The Bean id or name can be used for matching, and the wildcard "*" can be used;

Combined entry point expression

AspectJ used and (&), or (|), not (!) To combine the entry point expression.

In the Schema style, "&" must be replaced by the Escape Character "& amp;" in XML, which is inconvenient, therefore, Spring ASP provides and, or, and not to replace &, |, and ,!.

Example Execution :Use the "execution (Method Expression)" Matching Method to execute

Within : Use "( Type expression) "Matching Method execution within a specified type

This:Use "this (Type-qualified name)

The execution method that matches the current AOP proxy object type. Note that it is the type matching of the AOP proxy object, which may include the interface method or the matching method; note that the expression used in this must be a fully qualified type name. Wildcards are not supported.

Target:Use "target (Type Full qualified name)

Matching the execution method of the current target object type; note that it is the type matching of the target object, which does not include the introduced interface and the type Matching. Note that the expression used in the target must be a fully qualified type name, wildcards are not supported.

Args: Use "args (parameter type list )"

The input parameter that matches the currently executed method is the execution method of the specified type. Note that it matches the input parameter type rather than the parameter type that matches the method signature; the parameter in the parameter type list must be a fully qualified name of the type and is not supported by wildcards. args is a dynamic entry point, which has a high overhead and is not recommended in special cases.

@:Use "@ within (annotation type )"

Match the method that holds the specified annotation type. The annotation type must also be a fully qualified type name.

@ Target:Use "@ target (annotation type )"

Matches the execution method of the current target object type. The target object holds the specified annotation. The annotation type must also be a fully qualified type name.

@ Args:Use @ args (annotation List )"

Matches the execution of the specified Annotation with the input parameter of the currently executed method. The annotation type must also be a fully qualified type name.

@ Annotation:Use "@ annotation (annotation type )"

Bean:Use "bean (Bean id or name wildcard )"

The execution method of Bean objects matching specific names; Spring ASP extensions, no corresponding concepts in AspectJ

Reference pointcut

It indicates that other naming start points are referenced. Only the @ ApectJ style is supported, and the Schema style is not supported, as shown below:

I wrote a lot later than the original author, so I won't repost it here. For more information about spring, see the http://jinnianshilongnian.iteye.com/blog/1508589.

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.