Spring学习-06课SpringAOP 基于Schema的AOP支持( 基于XML的AOP支持)

76 阅读1分钟

1、 创建切面类 并注入为bean

使用

//@Component 

<bean class="com.kdy.aspects.LogAspect" name="aspectname"></bean>

2、关联方法实现代理

<aop:config>
    <aop:aspect ref="aspectname">
        <aop:pointcut id="cutAllService" expression="execution(*  com.kdy.service..*.*(..))"/>
        <aop:before method="before" pointcut="execution(*  com.kdy.service..*.*(..)) &amp;&amp;  @annotation(logger)"></aop:before>
        <aop:after method="after" pointcut-ref="cutAllService"></aop:after>
        <aop:after-returning method="afterReturning" pointcut-ref="cutAllService" returning="returnValue"></aop:after-returning>
        <aop:after-throwing method="afterThrow" pointcut-ref="cutAllService" throwing="ex"></aop:after-throwing>
        <aop:around method="arround" pointcut-ref="cutAllService"></aop:around>
    </aop:aspect>

</aop:config>

为什么推荐使用@Aspectj方式

image.png

组合切入点 xml无法实现 @Aspectj 可以

注意:xml文件中使用&& 实现 && 链接