Vernacular Spring (Elementary) --- AOP (execution expression) (rpm)

[Scanty, is to give yourself digging]

AOP content as the last one, let's briefly summarize see the writing on the cut surface expression method. The following contents that refer to other blog posts in advance thank you to the great God of the open source blog!

--------------------------------------------------------------------------------------------------------------------------------------------------------

1. We look at other blog and explained in this example

--------------------------------------------------------------------------------------------------------------------------------------------------------

execution(* com.sample.service.impl..*.*(..))

Explained as follows:

Symbol Meaning

execution ()                  body expression;

First a "*" symbol        indicates the return type of any value;

com.sample.service.impl AOP cut package name of the service, that is, part of our business
behind the package name ".." indicates that the current package and subpackages
second "*" indicates the class name, * ie all categories . Here can be customized, for example below there
. * (..) represents any method name, parameters parentheses, two points denote any parameter type


AspectJ expression of exection Summary:
The basic syntax is:

Execution (<Modifier Mode>? <return type model> <model method name> (<parameter mode>) <abnormal pattern>?) in addition to the return type of pattern, and a method name mode parameter mode, other items are optional .

Here, we suggest using Execution () function of various examples.


1) by the method signature definition pointcut

 execution(public * *(..))

All public methods matching the target class, but does not match SmartSeller and protected voidshowGoods () method. * A representative of the first return type, * represents a second method name, and the parameters .. The method of any of the representatives;

 

 execution(* *To(..))l

All methods to match the target To suffix. It matches the NaiveWaiter and NaughtyWaiter greetTo () and serveTo () method. * A representative of the first return type, and any method behalf * To To suffix;

 

2) class defined by the point of tangency

 execution(*com.baobaotao.Waiter.*(..))l

All methods Waiter matching interfaces, and it matches greetTo NaiveWaiter NaughtyWaiter class () and serveTo () method. * Represents a first return any type, com.baobaotao.Waiter * represents all methods Waiter interface.;

 

 execution(*com.baobaotao.Waiter+.*(..))l

Method Waiter interface and its implementation class for all matches, and it not only match NaiveWaiter NaughtyWaiter class greetTo () and serveTo () method of these two Waiter interface definition, but also matching NaiveWaiter # smile () and NaughtyWaiter # joke () which two methods are not defined in the interface Waiter.

 

3) packet type defined by the point of tangency

Class name pattern string, ". *" Denotes all the classes in the package, and ".. *" represents a package, all classes in the package descendants.

 execution(* com.baobaotao.*(..))l

Com.baobaotao packet matches all methods of all classes;

 

 execution(* com.baobaotao..*(..))l

Com.baobaotao matching package, all methods of all classes of the package under descendants, as all methods of all classes at com.baobaotao.dao, com.baobaotao.servier and com.baobaotao.dao.user packet match. ".." appears in the class name, must be followed by "*", said the package, all classes in the package sons;

 

 execution(* com..*.*Dao.find*(..))l

The method of any prefix matching package names package com name suffix a Dao lower class, to find a method name must be prefixed. The com.baobaotao.UserDao # findByUserId (), com.baobaotao.dao.ForumDao # findById () method matches the tangent point.

 

4) by the method defined in the reference tangent point

Cut-point expression method of the reference part is complex, you can use the "*" and ".." wildcard, wherein "*" represents any type of parameters, and ".." indicates the number of parameters and any type of parameter is not limited.

 

 execution(* joke(String,int)))l

The first parameter matches the joke (String, int) method, and Joke () method is String, the second argument is int. It matches NaughtyWaiter # joke (String, int) method. If the method of the reference type is a class under java.lang package, it may be used as the class name, or must be fully qualified class name, such as a joke (java.util.List, int);

 

 execution(* joke(String,*)))l

Joke match the target class () method that the first parameter is a String, the second parameter may be any type, such as a joke (Strings1, String s2) and joke (String s1, double d2) match, However joke (String s1, doubled2, String s3) that do not match;

 

 execution(* joke(String,..)))l

To match the target in joke () method that the first parameter is a String, can have any number back into the reference parameters and the type is not limited, as joke (Strings1), joke (String s1, String s2) and joke (String s1, double d2, Strings3) match.

 

 execution(* joke(Object+)))

Joke match the target class () method, the method has a parameter, and the parameter is a subclass of the class or type Object. It matches joke (Strings1) and joke (Client c). If we define the cut-off point is execution (* joke (Object)), only the matches joke (Object object) without matching joke (Stringcc) or joke (Client c).

-------------------------------------------------- -------------------------------------------------- --------------------------------
2. now, we look at the official documentation of this explanation and examples

 

 

 

 

 

 

So far, the vernacular Spring (Elementary) --- AOP (execution expression) end

Remarks:

The above expression we have no way of example of all, there is a demand but also please the reader, refer to interpret on their own official documents, perform configuration

 

References:

Spring's official website: http: //spring.io/docs

Other Bowen:
http://outofmemory.cn/code-snippet/3762/Spring-AOP-learn-example

http://tonl.iteye.com/blog/1966075
----------------
Disclaimer: This article is CSDN bloggers 'y-yg' original article, follow the CC 4.0 BY -SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/abcd898989/article/details/50809321

 

Guess you like

Origin www.cnblogs.com/muxi0407/p/11882586.html