1、环绕通知:
环绕通知相当于在aop:aspect中配置了aop:before和aop:after-returning,其中Object retVal=pjp.proceed()这行代码前的相当于aop:before,此代码后的相当于aop:after-returning中的配置
2、Advice parameters
Advice parameters例子:
1、配置文件:
<aop:config>
<aop:aspect id="moocAspectAOP" ref="moocAspect">
<aop:around method="roundInit" pointcut="execution(* com.wuyonghu.spring2.AspectBiz.init(String,int)) and args(bizName,times)"/>
</aop:aspect>
</aop:config>
2、切面中的方法:
public Object roundInit(ProceedingJoinPoint pjp,String bizName,int times) {
System.out.println(bizName+" "+times);
Object obj = null;
try {
System.out.println("around方法执行前");
obj = pjp.proceed();
System.out.println("around方法執行后");
} catch (Exception e) {
// TODO: handle exception
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return obj;
}
3、切入点中的方法:
public void init(String bizName,int times){
System.out.println("AspectBiz init:"+bizName+" "+times);
}
4、测试方法:
@Test
public void test1() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
AspectBiz biz=(AspectBiz) context.getBean("aspectBiz");
biz.init("海贼王",3);
}