The first thing to try is org.springframework.web.servlet.handler.SimpleMappingExceptionResolver up org.springframework.web.servlet.handler.SimpleMappingExceptionResolver to handle JasperException (or any other kind?). Strange, I could not get it to work (it seems that it is not involved in the stack at all).
Something like that:
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException"> <property name="exceptionMappings"> <props> <prop key=".AccessDeniedException">error403</prop> <prop key=".DataAccessException">error500</prop> <prop key=".NoSuchRequestHandlingMethodException">error404</prop> <prop key=".TypeMismatchException">error404</prop> <prop key=".MissingServletRequestParameterException">error404</prop> <prop key=".TimeoutException">errorTimeout</prop> <prop key=".JasperException">error500</prop> </props> </property> <property name="warnLogCategory" value="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" /> <property name="defaultStatusCode" value="500" /> </bean>
If this is not enough, you can always specify your own SimpleMappingExceptionResolver extension.
Now, if this does not work at all (this is not for me), you can provide your own javax.servlet.Filter , and it will certainly work (although it may not be "spring -est").
Something like:
public class MyExceptionHandlerFilter extends GenericFilterBean { public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException ,javax.servlet.ServletException { try { chain.doFilter(request, response); } catch (Exception e) {
}
In Spring 3/4 Java Config, you can put this class above in the @Configuration class, for example:
@Configuration public class MyConfig { ... @Bean public Filter exceptionSink() { return new MyExceptionHandlerFilter(); } ... }
(There are really a thousand ways to do this in Spring ... as usual). And if you use web.xml , it will look like this:
<filter> <filter-name>ExceptionHandlerFilter</filter-name> <filter-class>com.test.MyExceptionHandlerFilter</filter-class> </filter> ... <filter-mapping> <filter-name>ExceptionHandlerFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
If you can provide stacktrace errors, it can shed light on your filter chain (it will look for any "springframework" classes there) to see if there could be a less verbose / more spring - ish way to go about it. The chain will differ depending on your configuration (for example, you can see some spring-protective filters there if you use it, etc.).