![](https://csdnimg.cn/release/download_crawler_static/10827341/bg8.jpg)
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)
throws-pattern?
modifiers-pattern:方法的操作权限
declaring-type-pattern:方法所在的包
其中,除 ret-type-pattern 和 name-pattern 之外,其他都是可选的。上例中,execution(* com.spring.service.*.*(..))表示
com.spring.service 包下,返回值为任意类型;方法名任意;参数不作限制的所有方法。
最后说一下通知参数
可以通过 args 来绑定参数,这样就可以在通知(Advice)中访问具体参数了。例如,<aop:aspect>配置如下:
<aop:config>
<aop:aspect ref="xmlAspect">
<aop:pointcut id="simplePointcut"
expression="execution(* com.gupaoedu.aop.service..*(..)) and args(msg,..)" />
<aop:after pointcut-ref="simplePointcut" method="after"/>
</aop:aspect>
</aop:config>
上面的代码 args(msg,..)是指将切入点方法上的第一个 String 类型参数添加到参数名为 msg 的通知的入参上,这样就可以直接
使用该参数啦。
访问当前的连接点
在上面的 Aspect 切面 Bean 中已经看到了,每个通知方法第一个参数都是 JoinPoint。其实,在 Spring 中,任何通知(Advice)
方法都可以将第一个参数定义为 org.aspectj.lang.JoinPoint 类型用以接受当前连接点对象。JoinPoint 接口提供了一系列有用
的方法, 比如 getArgs() (返回方法参数)、getThis() (返回代理对象)、getTarget() (返回目标)、getSignature() (返回
正在被通知的方法相关信息)和 toString() (打印出正在被通知的方法的有用信息)。
5.6.2、SpringAOP 设计原理及源码分析
开始之前先上图,看看 Spring 中主要的 AOP 组件