切面AfterThrowing不执行

大表哥bettercong 2016-11-09 04:37:01
写了一个异常收集的方法
public void afterThrowing(Throwable ex) {
System.out.println("1111111111111111111111111111");
......
}

以上切面我配置在了service层的所有类

1、如果我从定时任务调用service层的方法,手动跑出一个异常
throw new Exception("1111111111111111111111");
是可以进入到 afterThrowing(Throwable ex) 这个方法中的

2、我从Controller层调用service层的方法,然后手动抛出异常
throw new Exception("1111111111111111111111");

为什么没有进入到afterThrowing方法中呢?

配置文件如下:

<bean id="throwsInterceptor" class="com.xxx.ThrowsAopInterceptor"></bean>

<aop:config>
<aop:pointcut expression="execution(* com.ddd..*(..))" id="servicePointcut"/>
<aop:aspect id="throwsAspect" ref="throwsInterceptor">
<aop:after-throwing throwing="ex" method="afterThrowing" pointcut-ref="servicePointcut" />
</aop:aspect>
</aop:config>


求指教,谢谢!
...全文
414 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
配置文件如下: <bean id="throwsInterceptor" class="com.xxx.ThrowsAopInterceptor"></bean> <aop:config> <aop:pointcut expression="execution(* com.ddd..*(..))" id="servicePointcut"/> <aop:aspect id="throwsAspect" ref="throwsInterceptor"> <aop:after-throwing throwing="ex" method="afterThrowing" pointcut-ref="servicePointcut" /> </aop:aspect> </aop:config>

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧