下面是aop:config的配置
<aop:config>
<aop:aspect ref="magician">
<aop:pointcut id="thinking"
expression="execution(*
com.springinaction.springidol.Volunteer.thinkOfSomething(String))
and args(thoughts)"
/>
<aop:before method="interceptThoughts"
arg-names="thoughts"
pointcut-ref="thinking"/>
</aop:aspect>
</aop:config>
下面是我的问题
1. 按照切点的表达式,我们可以知道thinkOfSomething(String)方法有一个String参数,那么在匹配切面中的方法的时候,根据配置可以知道方法名是interceptThoughts,那么再检查该方法是否有且只有一个String参数不就行了,为什么还要在切点中配置"args(thoughts)",在通知方法配置属性arg-names="thoughts",而且要求字符串“thoughts”是一致的,而不是作为一个占位。
2. 假设配置args(thoughts)只是为了说明该切点需要传递参数和传递参数的个数(比如说thoughts只是占位,表明传递第一个参数),那么根据参数的个数和对应的类型就可以匹配到通知方法了。那么,arg-names="thoughts" 就是多余的了。
上面就是我的疑问,有一种情况是我试验可以成功的,那就是切点不配置args(thoughts),通知方法不配置arg-names="thoughts",并且通知方法interceptThoughts是个无参函数,这个情况是可以的。
总而言之,关于通知方法的匹配逻辑我很模糊,希望大神指点。