我正在使用Spring MVC 4,Hibernate 4和c3p0来限制池数据库连接。我还实现了自定义异常解析器,该解析器将AnnotationMethodHandlerExceptionResolver
扩展到Tomcat,不会将日志返回到front(user)。但是,我注意到我的异常解析器无法处理由org.springframework.transaction.CannotCreateTransactionException
和org.hibernate.exception.GenericJDBCException
引起的异常,因为数据库连接池已耗尽,但是Tomcat将所有日志返回到最前面-用户可见,但是这是不想要的结果。我试图通过在doResolveException
中的覆盖方法AnnotationMethodHandlerExceptionResolver
中设置的断点来调试异常解析器,但应用程序不会在断点处停止。 Hibernate异常应该以不同的方式处理吗?如何在自定义异常解析器中处理它们?
public class MappingExceptionResolver extends AnnotationMethodHandlerExceptionResolver{
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handlerMethod, Exception exception) {
ModelAndView mav = super.doResolveException(request, response, handlerMethod, exception);
if (isEmpty(mav)) {
MappingResolveExceptionResult resolveResult = getResolveResult(request, exception);
response.setStatus(resolveResult.getResponseStatus());
mav = new ModelAndView(resolveResult.getView());
if (HttpStatus.valueOf(resolveResult.getResponseStatus()).series() != Series.REDIRECTION) {
mav.addObject("exception", exception);
mav.addObject("handler", handlerMethod);
}
}
return mav;
}
}