美文网首页
AOP-环绕通知

AOP-环绕通知

作者: Yanl__ | 来源:发表于2019-12-11 10:05 被阅读0次

步骤:
1.新建一个类继承MethodInterceptor,重写invoke方法

public class MyArround implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation arg0) throws Throwable {
        // 执行前置通知的操作
        System.out.println("环绕通知-前置");
        // 放行,调用切点
        Object result = arg0.proceed();
        // 执行后置通知的操作
        System.out.println("环绕通知-后置");
        return result;
    }
}

2.在Spring中配置

<bean id="myarround" class="com.steer.advice.MyArround"></bean>

<!--        配置环绕通知-->
<aop:advisor advice-ref="myarround" pointcut-ref="mypointcut"></aop:advisor>

相关文章

网友评论

      本文标题:AOP-环绕通知

      本文链接:https://www.haomeiwen.com/subject/bkqogctx.html