基于配置的AOP实现
Spring所有的切面和通知偶必须放在一个<aop:config>
内(可以配置包含多个元素),每一个<aop:config>
可以包含pointcut,advisor元素(它们必须按照这个顺序进行声明)
<aop:config>
风格的配置大量使用了Spring的自动代理机制
<bean id="moocAspect" class="com.imooc.aop.schema.advice.MoocAspect"></bean>
<bean id="aspectBiz" class="com.imooc.aop.schema.advice.biz.AspectBiz"></bean>
<aop:config>
<aop:aspect id="moocAspectAOP" ref="moocAspect">
</aop:aspect>
</aop:config>
<bean id="advice" class="com.xrq.aop.TimeHandler" />
<aop:config>
<aop:aspect id="aspect" ref="advice">
<aop:pointcut id="pointcut" expression="execution(* com.xrq.aop.HelloWorld.*(..))" />
<aop:before method="printTime" pointcut-ref="pointcut" />
<aop:after method="printTime" pointcut-ref="pointcut" />
</aop:aspect>
</aop:config>
配置切入点pointcut
之前说到Spring AOP或者Spring支持的AspectJ,这部分是都支持的,以下的是只有Spring AOP里边自己支持的
<bean id="moocAspect" class="com.imooc.aop.schema.advice.MoocAspect"></bean>
<bean id="aspectBiz" class="com.imooc.aop.schema.advice.biz.AspectBiz"></bean>
<aop:config>
<aop:aspect id="moocAspectAOP" ref="moocAspect">
<aop:pointcut id="moocPiontcut"
expression="execution(* com.imooc.aop.schema.advice.biz.*Biz.*(..))"/>
</aop:aspect>
</aop:config>
这里要匹配AspectBiz类里边所有的方法。
这里*Biz标识以Biz结尾的类,其实就是AspectBiz这个类。