SpringAOP切点表达式
-
切点表达式(aop最难部分)
-
execution(常用)
-
描述力度:描述具体到方法、参数、类型
-
举个栗子:
@Pointcut("execution(* com.llds.seek.SeekAspect.*.*(..))") public void s(){ }execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?) 这里问号表示当前项可以有也可以没有,其中各项的语义如下: *:代表(所有/任意) ..:代表任意参数,任意类型 modifiers-pattern:方法的可见性,如public,protected ret-type-pattern:方法得返回值类型,如int、void等 declaring-type-pattern:方法所在类的全路径名,如com.llds.service name-pattern:方法名类型,如show()、queryAllInfo() param-pattern:方法的参数类型,如String、int throws-pattern:方法抛出的异常类型,如Exception
-
-
within
- 描述力度:具体到一个类
-
this
- 代理对象
-
target
- 目标对象
-
args
-
描述力度:具体搜索某一个参数的类型
-
举个栗子
@Pointcut("args(java.lang.String)") public void s(){ //会寻找所有参数是String类型的参数 }
-
-
@annotation
-
描述力度:具体搜索指定加了指定注解的方法
-
举个栗子
@Pointcut("@annotation(org.springframework.stereotype.Service)") public void s(){ //会寻找所有方法上有@Service的方法 }
-
-
@within
-
描述力度:具体搜索加了指定注解的类
-
举个栗子
@Pointcut("@within(org.springframework.stereotype.Service)") public void s(){ //会寻找所有加了@Service的类进行切入 }
-
-
博客主要围绕SpringAOP切点表达式展开,指出切点表达式是AOP最难部分。介绍了execution、within、this、target、args、@annotation、@within等不同类型的切点表达式,说明了它们的描述力度,并给出了部分示例。
324

被折叠的 条评论
为什么被折叠?



