Expert Spring MVC and Web Flow

(Dana P.) #1
"-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="exceptionMappingForSingleController"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="mappedHandlers">
<set>
<ref bean="someController" />
</set>
</property>
<property name="exceptionMappings">
<props>
<prop key="ApplicationException">appErrorView</prop>
<prop key="SomeOtherException">someErrorView</prop>
<prop key="java.lang.Exception">genericErrorView</prop>
</props>
</property>
</bean>

<bean id="exceptionMappingForMultipleControllers"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="mappedHandlers">
<set>
<ref bean="anotherController" />
<ref bean="mainController" />
</set>
</property>
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">differentErrorView</prop>
</props>
</property>
</bean>
</beans>

Two exception resolvers are defined in the ApplicationContextin Listing 5-20. Each
defines a set of mapped handlers that will define when the exception resolver is applied. If an
exception resolver encounters an exception from a handler it is not mapped to, it will simply
ignore the exception. Note that this behavior is only for exception resolvers that are mapped
to at least one handler.
You can control the order in which the DispatcherServletwill call each exception
resolver. To do this, simply add a property named orderand set it to a positive integer. Any
exception resolvers not specified with an order will be randomly placed at the end of the
ordered list.
Listing 5-21 provides an example of setting an order priority.

96 CHAPTER 5 ■THE PROCESSING PIPELINE

Free download pdf