环绕通知(Schema- base方式)
2、实现步骤:
2.1 新建一个类实现 MethodInterceptor 接口
public class MyArround implements MethodInterceptor{ @Override public Object invoke(MethodInvocation arg0) throws Throwable { System.out.println("环绕--前置通知11111"); 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>