我設置了一個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 [[email protected]]: 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: [email protected]14f9>
[org.springframework.web.servlet.DispatcherServlet] - <Successfully completed request>
[org.springframework.web.context.support.XmlWebApplicationContext] - <Publishing event in context [o[email protected]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 [o[email protected]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>
你在瀏覽器中得到了什麼?一個空白頁面?一個堆棧跟蹤? – rodrigoap 2009-09-30 21:05:17
Spring 2.5.5比較麻煩。使用2.5.6,它堅如磐石。 – skaffman 2009-12-29 13:54:09