后通知怎么实现

解决方案 »

  1.   

    <aop:config>
    <!-- 定义切入点 -->???怎么写?
    <!-- 关于事务边界的设置,通常设置到业务层 -->
    <!-- 指定具体的包的路径  ........  -->
    <aop:pointcut id="myPointCut" expression="execution(* com.vance.service.impl.*.*(..))"/>

    <!-- 定义通知位置 -->
    <aop:advisor advice-ref="myAdvice" pointcut-ref="myPointCut"/>
    </aop:config>
      

  2.   


    <aop:aspect id="afterReturningExample" ref="aBean">
        <aop:pointcut id="businessService" 
              expression="execution(* com.xyz.myapp.service.*.*(..))"/>    <aop:after-returning 
          pointcut-ref="dataAccessOperation" 
          method="doAccessCheck"/>
              
        ...
        
    </aop:aspect>
      

  3.   

    后通知必须实现AfterReturningAdvice 接口,例如:public class CountingAfterReturningAdvice implements AfterReturningAdvice {
    private int count;
    public void afterReturning(Object returnValue, Method m, Object[] args, Object target)
    throws Throwable {
    ++count;
    }
    public int getCount() {
    return count;
    }
    }