我设置了一个id为“exceptionResolver”的bean,使其成为org.springframework.web.servlet.handler.SimpleMappingExceptionResolver的一个实例。然后我定义了两个属性,“defaultErrorView”和“exceptionMappings”。
据我了解,这应该捕获我的Web应用程序中抛出的任何异常并转发到我指定的视图。
这种情况没有发生,我得到的只是带有堆栈跟踪的标准tomcat 500错误页面。我究竟做错了什么?另外,我使用的是spring 2.5.5,我的所有控制器/ dao / etc ......都是使用spring注释定义的。
这是我的堆栈跟踪中的一个吐出。
[org.springframework.orm.hibernate3.SessionFactoryUtils] - <Closing Hibernate Session>
[org.hibernate.jdbc.ConnectionManager] - <releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]>
[org.hibernate.jdbc.ConnectionManager] - <transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!>
[org.springframework.web.servlet.handler.SimpleMappingExceptionResolver] - <Resolving exception from handler [controller.EditController@b512cb]: java.lang.NumberFormatException: null>
[org.springframework.web.servlet.handler.SimpleMappingExceptionResolver] - <Resolving to view 'errors/applicationErrorPg2' for exception of type [java.lang.NumberFormatException], based on exception mapping [java.lang.NumberFormatException]>
[org.springframework.web.servlet.handler.SimpleMappingExceptionResolver] - <Exposing Exception as model attribute 'exception'>
[org.springframework.web.servlet.DispatcherServlet] - <Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'errors/applicationErrorPg2'; model is {exception=java.lang.NumberFormatException: null}>
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:372)
at java.lang.Long.parseLong(Long.java:461)
at controller.EditController.createEditDto(EditController.java:169)
...
[org.springframework.web.servlet.DispatcherServlet] - <Rendering view [org.springframework.web.servlet.view.JstlView: name 'errors/applicationErrorPg2'; URL [/WEB-INF/jsps/errors/applicationErrorPg2.jsp]] in DispatcherServlet with name 'apps'>
[org.springframework.web.servlet.view.JstlView] - <Rendering view with name 'errors/applicationErrorPg2' with model {exception=java.lang.NumberFormatException: null} and static attributes {}>
[org.springframework.web.servlet.view.JstlView] - <Added model object 'exception' of type [java.lang.NumberFormatException] to request in view with name 'errors/applicationErrorPg2'>
[org.springframework.web.servlet.view.JstlView] - <Forwarding to resource [/WEB-INF/jsps/errors/applicationErrorPg2.jsp] in InternalResourceView 'errors/applicationErrorPg2'>
[org.springframework.web.servlet.DispatcherServlet] - <Cleared thread-bound request context: org.springframework.security.wrapper.SavedRequestAwareWrapper@4814f9>
[org.springframework.web.servlet.DispatcherServlet] - <Successfully completed request>
[org.springframework.web.context.support.XmlWebApplicationContext] - <Publishing event in context [org.springframework.web.context.support.XmlWebApplicationContext@53d4bf]: ServletRequestHandledEvent: url=[/app/edit.do]; client=[127.0.0.1]; method=[GET]; servlet=[apps]; session=[A459510CAB03A4868344995A602CFF27]; user=[UPDATE]; time=[94ms]; status=[OK]>
[org.springframework.web.context.support.XmlWebApplicationContext] - <Publishing event in context [org.springframework.web.context.support.XmlWebApplicationContext@12489c0]: ServletRequestHandledEvent: url=[/app/edit.do]; client=[127.0.0.1]; method=[GET]; servlet=[apps]; session=[A459510CAB03A4868344995A602CFF27]; user=[UPDATE]; time=[94ms]; status=[OK]>
[org.springframework.security.ui.ExceptionTranslationFilter] - <Chain processed normally>
[org.springframework.security.context.HttpSessionContextIntegrationFilter] - <SecurityContextHolder now cleared, as request processing completed>
答案 0 :(得分:3)
由于2.5.5版本中的问题,Spring异常解析程序无法在tomcat中呈现异常视图。请参阅以下故障单以获取详细信息。
答案 1 :(得分:0)
问题似乎是Spring版本2.5.5。我将依赖项更改为2.5.1和2.5.6.sec01(单独),转发按预期工作。
答案 2 :(得分:0)
虽然这可能不是您特定问题的答案,但我发现大多数在线文档和示例都是指使用
org.springframework.web.servlet.handler.SimpleMappingExceptionResolver
但如果您在portlet环境中运行,则需要使用
org.springframework.web.portlet.handler.SimpleMappingExceptionResolver
希望这能让人节省几个小时的头脑。