aop point-cut表达式
好多博客写的云里雾里,大多都有一点毛病。大家还是以官网为准
官网截图
modifiers-pattern:修饰符
ret-type-pattern:方法返回类型
declaring-type-pattern:指定方法所属的类
name-pattern:方法名
param-pattern:参数列表
throws-pattern:抛出的异常
All parts except the returning type pattern (ret-type-pattern
in the preceding snippet), the name pattern, and the parameters pattern are optional.
除ret-type-pattern、 name pattern、param-pattern外都是可选参数
The returning type pattern determines what the return type of the method must be in order for a join point to be matched. *
is most frequently used as the returning type pattern.It matches any return type. A fully-qualified type name matches only when the method returns the given type.
ret-type-pattern决定方法必须要返回的类型。*最常用,匹配任何返回类型。方法返回类型必须与完全限定类型名匹配
The name pattern matches the method name.You can use the *
wildcard as all or part of a name pattern.
name pattern匹配方法名称。可以用通配符*作为全部或部分name pattern.
If you specify a declaring type pattern, include a trailing .
to join it to the name pattern component.
如果你声明一个declaring-type-pattern,为了连接 name pattern应该加上“.”,即declaring-type-pattern.name-patterm
The parameters pattern is slightly more complex: ()
matches a method that takes no parameters, whereas (..)
matches any number (zero or more) of parameters. The (*)
pattern matches a method that takes one parameter of any type. (*,String)
matches a method that takes two parameters. The first can be of any type, while the second must be a String
.
参数格式parameters pattern稍微复杂一点,
()匹配无参方法。
而(..)匹配任何数量(0个或多个)参数。
(*)匹配任何类型的一个参数
(*,string)匹配两个参数,前面是任何类型,第二个必须是字符串
-
The execution of any public method:
execution(public * *(..))
-
The execution of any method with a name that begins with
set
:execution(* set*(..))
-
The execution of any method defined by the
AccountService
interface:execution(* com.xyz.service.AccountService.*(..))
-
The execution of any method defined in the
service
package:execution(* com.xyz.service.*.*(..))
-
The execution of any method defined in the service package or one of its sub-packages:service 包和其子包(任意层?)下的所有方法
execution(* com.xyz.service..*.*(..))
-
Any join point (method execution only in Spring AOP) within the service package:
within(com.xyz.service.*)
-
Any join point (method execution only in Spring AOP) within the service package or one of its sub-packages:
within(com.xyz.service..*)
-
Any join point (method execution only in Spring AOP) where the proxy implements the
AccountService
interface:this(com.xyz.service.AccountService)
本文来自博客园,作者:每天都要学一点,欢迎讨论和转载,转载请注明原文链接:https://www.cnblogs.com/yanan7890/p/10570584.html