public class Target implements TargetInterface
{
@Override
public void save()
{
System.out.println("save running...");
throw new ClassCastException();
}
public void save2()
{
System.out.println("save2 running...");
}
}
切面:
public class MyAspect
{
public void afterThrowing()
{
System.out.println("异常抛出");
}
public void after()
{
System.out.println("最终通知");
}
}
<!--配置织入:告诉spring 哪些方法(切入点)需要进行哪些增强(前置增强,后置增强...)-->
<aop:config><!--配置aop-->
<!--配置切面(切入点+通知)-->
<aop:aspect id="myAspect" ref="myAspect"><!--声明切面-->
<aop:pointcut id="save" expression="execution(* aop.*.save(..))"/><!--抽取切点表达式-->
<aop:after-throwing method="afterThrowing" pointcut-ref="save"></aop:after-throwing>
<aop:after method="after" pointcut-ref="save"></aop:after>
</aop:aspect>
</aop:config>
总结