码迷,mamicode.com
首页 > 其他好文 > 详细

基于Schema方式的5种通知类型

时间:2016-05-31 23:46:11      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

<aop:config>
        <!--配置切入点-->
        <aop:pointcut id="pointcut" expression="execution(* com.itany.service.impl..*.*(..))"/>
        <!--配置切面-->
        <aop:aspect ref="testAspect">
            <!--前置通知-->
            <aop:before pointcut-ref="pointcut" method="beforeAdvice"/>
            <!--后置最终通知-->
            <aop:after pointcut="execution(* com.itany.service.impl..*.*(..))" method="afterFinallyAdvice"/>
            <!--后置返回通知-->
            <aop:after-returning pointcut="execution(* com.itany.service.impl.*.sayAfterReturning*(..))"
                         method="afterReturningAdvice" 
                         arg-names="obj"
                         returning="obj"/>
            <!--后置异常通知-->
            <aop:after-throwing pointcut="execution(* com.itany.service.impl.*.sayAfterThrowing*(..))"
                                method="afterThrowingAdvice" 
                                arg-names="excep"
                                throwing="excep"/>
            <!--环绕通知 第一个参数必须是org.aspectj.lang.ProceedingJoinPoint类型-->                    
            <aop:around pointcut="execution(* com.itany.service.impl.*.sayAround*(..))"
                        method="aroundAdvice"/>                    
        </aop:aspect>
    </aop:config>

说明:

  • execution( com.itany.service.impl...*(..))表示impl包下任何方法
  • execution( com.itany.service.impl..sayAfterThrowing*(..))这表示选取某个特定的方法
  • arg-names属性中的取值和调用方法的参数名不一定要相同,可以随便取个
  • 环绕通知 第一个参数必须是org.aspectj.lang.ProceedingJoinPoint类型
 

基于Schema方式的5种通知类型

标签:

原文地址:http://www.cnblogs.com/JavaTWW/p/5547820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!