为什么我的输入结果和视频里的不一样?(Around advice)
我的输出结果(代码是一样的):
MoocAspect before.
MoocAspect aroud 1.
AspectBiz biz.
MoocAspect afterReturning.
MoocAspect after.
MoocAspect aroud 2.
我的输出结果(代码是一样的):
MoocAspect before.
MoocAspect aroud 1.
AspectBiz biz.
MoocAspect afterReturning.
MoocAspect after.
MoocAspect aroud 2.
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;
}
配置文件如下:
<?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>
举报