1. 只有当切点报异常才能触发异常通知
2. 在 spring 中有 AspectJ 方式提供了异常通知的办法.
2.1 如果希望通过 schema-base 实现需要按照特定的要求自己编写方法
3. 实现步骤:
3.1 新建类,在类写任意名称的方法
public class MyThrowAdvice{
public void myexception(Exception e1){
System.out.println("执行异常通知"+e1.getMessage());
}
}
3.2 在 spring 配置文件中配置
3.2.1 <aop:aspect>的 ref 属性表示:方法在哪个类中.
3.2.2 <aop:xxx/>表示什么通知
3.2.3 method: 当触发这个通知时,调用哪个方法
3.2.4 throwing: 异常对象名,必须和通知中方法参数名相同(可不在通知中声明异常对象)
<bean id="mythrow" class="com.bjsxt.advice.MyThrowAdvice"></bean>
<aop:config>
<aop:aspect ref="mythrow">
<aop:pointcut expression="execution(* com.bjsxt.test.Demo.demo1())" id="mypoint"/>
<aop:after-throwing method="myexception" pointcut-ref="mypoint" throwing="e1"/>
</aop:aspect>
</aop:config>
<bean id="demo" class="com.bjsxt.test.Demo"></bean>