spring aop 捕获异常
来源:互联网 发布:淘宝知识产权侵权申诉 编辑:程序博客网 时间:2024/06/05 04:21
<bean id="exceptionHandler" class="highsoft.uip.common.ExceptionHandler" />
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
<!-- 这里配置切入点,可以为正则表达式 .*DAOImpl\.delete.*-->
<bean id="exceptionHandlereAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref bean="exceptionHandler"/>
</property>
<property name="patterns">
<list>
<value>.*.*</value>
</list>
</property>
</bean>
public class ExceptionHandler implements ThrowsAdvice {
/**
* Owner
* 参数解释 Method method 执行的方法
* Object[] args 方法参数
* Object target 代理的目标对象
* Throwable throwable 产生的异常
*
*/
public void afterThrowing(Method method, Object[] args, Object target, RuntimeException throwable) {
System.out.println("产生异常的方法名称: " + method.getName());
for(Object o:args){
System.out.println("方法的参数: " + o.toString());
}
System.out.println("代理对象: " + target.getClass().getName());
System.out.println("抛出的异常: " + throwable.getMessage()+">>>>>>>" + throwable.getCause());
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
if(request.getAttribute("exception")==null){
ArrayList<String> eptList=new ArrayList<String> ();
request.setAttribute("exception", eptList);
}
request.setAttribute("exception",(( ArrayList<String>)request.getAttribute("exception")).add(throwable.getMessage()));
System.out.println("异常详细信息: "+throwable.fillInStackTrace());
}
}
注意:此方法只对spring配置的bean进行捕获异常
- spring aop 捕获异常
- Spring AOP 抛出增强捕获异常
- aop异常捕获
- 项目中使用SPRING AOP方式统一捕获异常
- 通过spring的aop注解实现所有方法异常的捕获处理,sqlite SQLITE_BUSY异常
- Spring JdbcTemplate捕获异常
- Spring AOP配置声明式事务,数据业务层捕获异常,事务控制处理
- Spring Aop 异常
- Spring Aop异常处理
- Spring AOP xml异常
- spring aop 异常记录
- Spring代理/aop异常
- Spring Mvc全局异常捕获
- spring mvc 全局异常捕获
- spring事务异常捕获问题
- Spring 异常捕获+log4j日志
- spring MVC异常捕获机制
- spring boot 全局异常捕获
- iOS开发如何实现消息推送机制
- 使用PhoneGap开发Android程序小记
- HDU 1401 Solitaire(双向BFS)
- lds链接脚本***三篇博客
- 简单3D立体效果
- spring aop 捕获异常
- ubuntu更改主机名,修改IP地址
- (转)Android Animations动画使用详解
- [关于jQuery的事件代理] jQuery的.bind()、.live()和.delegate()之间区别
- c++小知识点
- Flash AS3)分享一个ActionScript3的倒影类
- 秒杀多线程第十六篇 多线程十大经典案例之一 双线程读写队列数据
- 用户空间与内核空间数据交换的方式(1)------debugfs
- Google App Engine