Expert Spring MVC and Web Flow

(Dana P.) #1

The path matching algorithms default to the same mechanism as
BeanNameUrlHandlerMapping, so the patterns used to map URLs to request handlers remains
the same.
To use a SimpleUrlHandlerMapping, simply declare it inside your ApplicationContext.
The DispatcherServletwill recognize it by type, and it will not create an instance of
BeanNameUrlHandlerMapping. This means that if you wish to use both mapping strategies,
you must declare both in your ApplicationContext.


■Tip The DispatcherServletwill chain handler mapping strategies, allowing you to mix and match as
you see fit. Handler mappings also implement the Orderedinterface.


To begin, we will port the previous mapping to use a SimpleUrlHandlerMapping, as shown
in Listing 5-13.


Listing 5-13.SimpleUrlHandlerMapping Example


<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">








<bean id="homeController"
class="com.apress.expertspringmvc.flight.web.HomeController">




Unfortunately, it is a bit more verbose when mapping two different URL patterns to the
same request handler. You must create two different mappings, as shown in Listing 5-14.


Listing 5-14.Two Mappings for One Controller with SimpleUrlHandlerMapping


<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">









CHAPTER 5 ■THE PROCESSING PIPELINE 91
Free download pdf