為什么我的輸入結(jié)果和視頻里的不一樣?(Around advice)
我的輸出結(jié)果(代碼是一樣的):
MoocAspect before.
MoocAspect aroud 1.
AspectBiz biz.
MoocAspect afterReturning.
MoocAspect after.
MoocAspect aroud 2.
我的輸出結(jié)果(代碼是一樣的):
MoocAspect before.
MoocAspect aroud 1.
AspectBiz biz.
MoocAspect afterReturning.
MoocAspect after.
MoocAspect aroud 2.
2015-03-04
舉報(bào)
2015-10-19
因?yàn)槭请S機(jī)的,你可以用order設(shè)置順序,詳見spring文檔。文檔中的finally僅僅表示一定會被執(zhí)行,并不代表最后被執(zhí)行
2015-03-04
public void before()
{
System.out.println("MoocAspect before.");
}
public void afterReturning()
{
System.out.println("MoocAspect afterReturning.");
}
public void afterThrowing()
{
System.out.println("MoocAspect afterThrowing.");
}
public void after()
{
System.out.println("MoocAspect after.");
}
public Object around(ProceedingJoinPoint pjp)
{
Object obj = null;
try
{
System.out.println("MoocAspect aroud 1.");
obj = pjp.proceed();
System.out.println("MoocAspect aroud 2.");
} catch (Throwable e)
{
e.printStackTrace();
}
return obj;
}
2015-03-04
你定義的順序和結(jié)果是一樣的么?你看一下你的定義順序,都是按定義的順序執(zhí)行的。
2015-03-04
配置文件如下:
<?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-3.1.xsd
">
<bean id="moocAspect" class="com.yxq.aop.MoocAspect"></bean>
<bean id="aspectBiz" class="com.yxq.aop.AspectBiz"></bean>
<aop:config>
? <aop:aspect id="moocAspectAOP" ref="moocAspect">
? ? ?<aop:pointcut expression="execution(* com.yxq.aop.*Biz.*(..))" id="moocPointcut"/>
? ? ?<aop:before method="before" pointcut-ref="moocPointcut"/>
? ? ?<aop:after-returning method="afterReturning" pointcut-ref="moocPointcut"/>
? ? ?<aop:after-throwing method="afterThrowing" pointcut-ref="moocPointcut"/>
? ? ?<aop:after method="after" pointcut-ref="moocPointcut"/>
? ? ?<aop:around method="around" pointcut-ref="moocPointcut"/>
? </aop:aspect>
</aop:config>
</beans>
2015-03-04
你的配置文件也要和視頻的一樣