Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The way we handle this is to have a custom exception resolver class that handles any exceptions that are not caught by other handlers - it implements HandlerExceptionResolver, Ordered.</p> <p>We declare a separate SimpleMappingExceptionResolver bean that catches specific exceptions.</p> <p>The ordering is such that our custom resolver runs after the SimpleMappingExceptionResolver.</p> <p>The effect is that specified exceptions (e.g. AccessDeniedException) are handled by SimpleMappingExceptionResolver and directed to the appropriate pages.</p> <p>Any other run time exceptions are handled by the custom resolver, which forwards to a generic error page.</p> <pre><code>&lt;bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"&gt; &lt;property name="exceptionMappings"&gt; &lt;props&gt; &lt;prop key="org.springframework.security.AccessDeniedException"&gt;accessDenied&lt;/prop&gt; &lt;prop key="org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException"&gt;accessDenied&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="order" value="0"/&gt; &lt;/bean&gt; &lt;bean class="package.to.your.handler.DefaultExceptionResolver"&gt; &lt;property name="order" value="1"/&gt; &lt;/bean&gt; </code></pre> <p>This arrangement allows you to catch as many exceptions as you like (I catch 2 here, AccessDenied and HibernateOptimisticLockingFailureException) using the Spring resolver and everything else is caught by the custom resolver. In the accepted solution above, you would have to write more Java code to catch exceptions other than AccessDenied.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload