views:

1014

answers:

3

I set up a bean with an id of "exceptionResolver" made it an instance of org.springframework.web.servlet.handler.SimpleMappingExceptionResolver. Then I define two properties, "defaultErrorView" and "exceptionMappings".

As I understand it this should catch any exceptions thrown in my web application and forward to the view I've specified.

This is not happening, all I get is the standard tomcat 500 error page with stack trace. what am I doing wrong? Additionally, I'm using spring 2.5.5 and all of my controllers/dao/etc... are defined using spring annotations.

Here's a spit out of my stack trace.

[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>
A: 

The problem appears to be with Spring version 2.5.5. I changed my dependency to 2.5.1 and 2.5.6.sec01 (separately) and the forwarding worked as expected.

oneBelizean
A: 

While this may not be the answer to your specific problem, I just discovered that most documentation and examples online refer to using

org.springframework.web.servlet.handler.SimpleMappingExceptionResolver

but if you're running in a portlet environment you need to use

org.springframework.web.portlet.handler.SimpleMappingExceptionResolver

Hopefully that'll save somebody a couple of hours of head-scratching.

Lyle
+1  A: 

Spring exception resolver not rendering exception view in tomcat due to issue in 2.5.5 release.Please refer following ticket for details.

http://jira.springframework.org/browse/SPR-4973

Alwin