基于XML的Spring AOP实现demo

接上篇基于注解的demo, 相关AOP的介绍就不复述了,详情可以点击下方链接,http://www.jianshu.com/p/66d21dae6a68

  • 运行环境 : 在之前写的环境中http://www.jianshu.com/p/dc9ac263e60d

  • 将上篇中的AspectjLog的注解都去掉,其他不变

  • 在my-spring-servlet.xml中,加入aop相关的命名空间.

xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"
  • 在my-spring-servlet.xml中加入切点相关的定义
    <!--启用AspectJ自动代理-->
    <aop:aspectj-autoproxy/>

    <bean id="AspectjLog" class="com.sam.aop.aspectj.AspectjLog"/>
    <aop:config proxy-target-class="true">
        <aop:aspect id="log" ref="AspectjLog">
            <aop:pointcut id="logAop"
                          expression="execution(* com.sam.aop.service.AspectService.sayHello(..)) and args(email)"/>
            <aop:before method="logBefore" pointcut-ref="logAop"/>
            <aop:after method="logAfter" pointcut-ref="logAop"/>
            <aop:after-returning method="logAfterReturning" pointcut-ref="logAop"/>
            <aop:after-throwing method="logAfterThrow" pointcut-ref="logAop"/>
            <aop:around method="logAfterThrow"  pointcut-ref="logAop"/>
        </aop:aspect>
    </aop:config>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容