加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AOP 环绕通知

发布时间:2020-12-16 23:39:43 所属栏目:百科 来源:网络整理
导读:? 环绕通知(Schema- base方式) 1、把前置通知和后置通知都写到一个通知中,组成了环绕通知 2、实现步骤: 2.1 新建一个类实现 MethodInterceptor 接口 public class MyArround implements MethodInterceptor{ @Override public Object invoke(MethodInvoca

?

环绕通知(Schema- base方式)

  1、把前置通知和后置通知都写到一个通知中,组成了环绕通知

  2、实现步骤:

    2.1 新建一个类实现 MethodInterceptor 接口

public class MyArround implements MethodInterceptor{
    @Override
    public Object invoke(MethodInvocation arg0) throws Throwable {
        System.out.println("环绕--前置通知22222");
        Object result = arg0.proceed();//放行,调用切点方式
        System.out.println("环绕--后置通知222");
        return result;
    }   
}

    2.2 配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
        
        <bean id="myarround" class="com.bjsxt.advice.MyArround"></bean>
        <bean id="demo" class="com.bjsxt.test.Demo"></bean>
        <aop:config>
            <aop:pointcut expression="execution(* com.bjsxt.test.Demo.demo1())" id="mypoint"/>
            <aop:advisor advice-ref="myarround" pointcut-ref="mypoint"/>
        </aop:config>
        
  </beans>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读