- 浏览: 238410 次
- 性别:
- 来自: 皇城根儿下
文章分类
最新评论
-
悦悦余音:
楼主妙笔生花的文章解决了我的问题
hessian http response code:411 -
297434791:
返回对象有警告··返回String就没警告了,什么原因
hessian异常 -
lsjinpeng:
这个中文乱码怎么弄啊?
Kaptcha使用 -
zcs540061627:
wangjian95 写道我也遇到了这个问题
2012-7-1 ...
hessian异常 -
wangjian95:
哈哈,哥刚试了,数组是可以的,嘎嘎
hessian异常
最近使用spring mvc开发一个web系统,发现在controller里发生未捕获异常时不出日志。
分析DispatcherServlet,初始化handlerExceptionResolvers
分析DispatcherServlet,分发处理请求
关于异常处理的配置:
spring mvc异常设置http://fancyboy2050.iteye.com/blog/965663
分析DispatcherServlet,初始化handlerExceptionResolvers
/** * Initialize the strategy objects that this servlet uses. * <p>May be overridden in subclasses in order to initialize * further strategy objects. */ protected void initStrategies(ApplicationContext context) { initMultipartResolver(context); initLocaleResolver(context); initThemeResolver(context); initHandlerMappings(context); initHandlerAdapters(context); // 初始化异常处理支持器 initHandlerExceptionResolvers(context); initRequestToViewNameTranslator(context); initViewResolvers(context); } // 进入初始化处理方法,具体内容就不贴了,主要是先到上下文中搜寻我们自己定义的ExceptionResolvers,如果没有自定义的resolvers,从默认配置中读取。 private void initHandlerExceptionResolvers(ApplicationContext context) // 从默认策略中取得默认配置,从DispatcherServlet.properties文件中取得相关的配置策略,但是在spring2.5的mvc jar包中properties文件中没有HandlerExceptionResolver的默认配置,返回一个EmptyList给handlerExceptionResolvers protected List getDefaultStrategies(ApplicationContext context, Class strategyInterface)
分析DispatcherServlet,分发处理请求
// 从dispatch方法中看到,系统对请求进行具体的逻辑处理部分被catch住了一次exception,然后会使用servlet持有的ExceptionResolver进行处理 protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpServletRequest processedRequest = request; HandlerExecutionChain mappedHandler = null; int interceptorIndex = -1; // Expose current LocaleResolver and request as LocaleContext. LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext(); LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable); // Expose current RequestAttributes to current thread. RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable); if (logger.isTraceEnabled()) { logger.trace("Bound request context to thread: " + request); } try { ModelAndView mv = null; boolean errorView = false; try { processedRequest = checkMultipart(request); // Determine handler for the current request. mappedHandler = getHandler(processedRequest, false); if (mappedHandler == null || mappedHandler.getHandler() == null) { noHandlerFound(processedRequest, response); return; } // Apply preHandle methods of registered interceptors. HandlerInterceptor[] interceptors = mappedHandler.getInterceptors(); if (interceptors != null) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandle(processedRequest, response, mappedHandler.getHandler())) { triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, null); return; } interceptorIndex = i; } } // Actually invoke the handler. HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); // Do we need view name translation? if (mv != null && !mv.hasView()) { mv.setViewName(getDefaultViewName(request)); } // Apply postHandle methods of registered interceptors. if (interceptors != null) { for (int i = interceptors.length - 1; i >= 0; i--) { HandlerInterceptor interceptor = interceptors[i]; interceptor.postHandle(processedRequest, response, mappedHandler.getHandler(), mv); } } } catch (ModelAndViewDefiningException ex) { logger.debug("ModelAndViewDefiningException encountered", ex); mv = ex.getModelAndView(); } // 这里catch住controller抛出的异常,使用持有的ExceptionResolver处理,当没有配置自己的处理器时,程序会将异常继续往上抛出,最终交给我们的容器处理 catch (Exception ex) { Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null); mv = processHandlerException(processedRequest, response, handler, ex); errorView = (mv != null); } // Did the handler return a view to render? if (mv != null && !mv.wasCleared()) { render(mv, processedRequest, response); if (errorView) { WebUtils.clearErrorRequestAttributes(request); } } else { if (logger.isDebugEnabled()) { logger.debug("Null ModelAndView returned to DispatcherServlet with name '" + getServletName() + "': assuming HandlerAdapter completed request handling"); } } // Trigger after-completion for successful outcome. triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, null); } // 当没有配置ExceptionResolver时,异常将到达这里,最终抛出 catch (Exception ex) { // Trigger after-completion for thrown exception. triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex); throw ex; } catch (Error err) { ServletException ex = new NestedServletException("Handler processing failed", err); // Trigger after-completion for thrown exception. triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex); throw ex; } finally { // Clean up any resources used by a multipart request. if (processedRequest != request) { cleanupMultipart(processedRequest); } // Reset thread-bound context. RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable); LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable); // Clear request attributes. requestAttributes.requestCompleted(); if (logger.isTraceEnabled()) { logger.trace("Cleared thread-bound request context: " + request); } } }
关于异常处理的配置:
spring mvc异常设置http://fancyboy2050.iteye.com/blog/965663
发表评论
-
xmemcached 一致性hash
2012-12-11 18:22 0应用中使用xmemcached做为memcached的客户端, ... -
spring mvc 内存泄露
2012-12-11 16:30 4475有一个项目使用了spring mvc,以前因为各种原因一两个月 ... -
spring mvc annotation-driven
2012-11-08 12:03 2368使用spring mvc时,我们会在配置文件里添加<mv ... -
hessian spring overloadEnabled
2012-11-06 17:40 2552用spring+hessian构建远程服务,遇到有的服务接口存 ... -
hessian http response code:411
2012-11-06 17:31 4673记录一个很久以前的遇到的一个关于hessian的问题。 用 ... -
htmlunit抓取小说网站JS加载内容
2012-10-31 13:25 6579http://www.17k.com/chapter/76 ... -
关于spring jdbcTemplate取得LAST_INSERT_ID
2012-03-16 18:38 6264spring的jdbctemplate提供的方案: Key ... -
spring mvc请求映射关系处理
2012-01-04 18:05 77911:看DispatcherServlet的初始化策略 pr ... -
取得用户IP地址
2011-11-17 12:45 1258public static String getIpAdd ... -
泛型类的编译导致的错误
2011-10-25 16:16 1323这是前段时间遇到的一个问题,确定是因为泛型编译导致的,但是特别 ... -
Kaptcha使用
2011-08-11 18:32 12087简单的装备起来很简单,网上一大把,就不说了。 但是许多时候因为 ... -
spring-JavaMailSenderImpl
2011-07-12 16:11 2772使用spring的JavaMailSenderImpl J ... -
分库主键设计-Mysql
2011-07-06 18:21 3071常见的两种方案,遍布网络: 第一种: replace方案,m ... -
resin容器配置影响listener加载时机
2011-06-08 17:57 1539项目使用resin容器,发现resin容器启动时不加载list ... -
java求质数
2011-04-12 17:19 1363这两天JE求质数的帖子火了好几个哈 先介绍下质数的解释: 就 ... -
spring mvc异常设置
2011-03-17 18:10 15370spring mvc异常设置,做个记录 此段代码ZZ ... -
去除标签段的小代码
2011-03-14 15:45 1037private String removeImg(Str ... -
非注入方式取得spring注入bean的util类实现
2011-03-14 15:07 4733import org.springframework.be ... -
java.util.Set转换为Object[]
2011-03-10 14:49 1192Set<String> set = map.k ... -
java几种单例模式
2010-11-04 15:41 13381:饿汉 public class SingletonEx ...
相关推荐
spring mvc异常处理,详细参考http://blog.csdn.net/xiejx618/article/details/41918611
spring mvc统一处理异常,通过@ControllerAdvice+@ExceptionHandler
spring mvc让servlet容器直接处理异常.详细看:http://blog.csdn.net/xiejx618/article/details/41695255
1.创建第一个 Spring MVC 程序案例 2.Spring MVC @RequestMapping 注解案例 3.Spring MVC 请求参数的获取案例 4.Spring MVC 域对象共享数据案例 5.Spring MVC @ModelAttribute 注解案例 ...15.Spring MVC 异常处理案例
十一、spring mvc 如何实现全局的异常处理? 十二、spring mvc 如何把全局异常记录到日志中? 十三、如何给spring3 MVC中的Action做JUnit单元测试? 十四、spring mvc 转发与重定向 十五、spring mvc 处理ajax请求 ...
十一、spring mvc 如何实现全局的异常处理? 十二、spring mvc 如何把全局异常记录到日志中? 十三、如何给spring3 MVC中的Action做JUnit单元测试? 十四、spring mvc 转发与重定向 十五、spring mvc 处理ajax请求 ...
第3篇是Spring MVC技术入门,包括Spring MVC的背景介绍、架构整体剖析、环境搭建、处理器与映射器的讲解、前端控制器的源码分析、多种视图解析器的介绍、请求映射与参数绑定的介绍、Validation校验与异常处理和拦截...
十一、spring mvc 如何实现全局的异常处理? 十二、spring mvc 如何把全局异常记录到日志中? 十三、如何给spring3 MVC中的Action做JUnit单元测试? 十四、spring mvc 转发与重定向 十五、spring mvc 处理ajax请求...
NULL 博文链接:https://gaojiewyh.iteye.com/blog/1297746
spring-rest-exception-handler, 一个方便的RESTful api Spring MVC 异常 spring REST异常处理程序 这个项目的目的是为for提供一个方便的异常处理程序( 解析器),它满足了错误响应的最佳实践。 处理自定义异常。...
那么,能不能将所有类型的异常处理从各处理过程解耦出来,这样既保证了相关处理过程的功能较单一,也实现了异常信息的统一处理和维护?答案是肯定的。下面将介绍使用Spring MVC统一处理异常的解决和实现过程。
Spring Boot & Spring MVC 异常处理的N种方法 参考文档: Spring Boot 1.5.4.RELEASE Spring framework 4.3.9.RELEASE 默认行为 根据Spring Boot官方文档的说法: For machine clients it will produce a JSON ...
主要给大家介绍了关于Spring MVC异常处理机制的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Spring MVC具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
Spring MVC--9.自定义拦截器、异常处理
NULL 博文链接:https://cgs1999.iteye.com/blog/1547197
《Spring MVC 3.0实战指南》,参考《Spring 3.x企业应用开发实战》。 内容简介: 1、Spring MVC框架简介 2、HTTP请求地址映射 3、HTTP请求数据的绑定 4、数据转换、格式化、校验 5、数据模型控制 6、视图及解析器 7...
Spring 异常处理 Spring MVC 有两个主要方式来处理在调用 MVC 控制器(译注:Controller,下文统一为控制器)时抛出的异常:HandlerExceptionResolver 和 @ExceptionHandler 注解。 ...
在 Web 开发中, 我们经常会需要处理各种异常,这篇文章主要介绍了详解Spring MVC/Boot 统一异常处理最佳实践,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
《Spring MVC 3.0实战指南》,参考《Spring 3.x企业应用开发实战》。 内容简介: 1、Spring MVC框架简介 2、HTTP请求地址映射 3、HTTP请求数据的绑定 4、数据转换、格式化、校验 5、数据模型控制 6、视图及...