I’m running Spring MVC 3.x and I have one Controller with RequestMapping annotations (DefaultAnnotationHandlerMapping) and I have one ServletForwardingController with some additional mappings via SimpleUrlHandlerMapping. When I boot up my application, I see the following:
...
13:24:17,747 INFO [DefaultAnnotationHandlerMapping] Mapped URL path [/{query}] onto handler [com.foo.controllers.BarController@1b20a36]
13:24:17,997 INFO [SimpleUrlHandlerMapping] Root mapping to handler [org.springframework.web.servlet.mvc.ParameterizableViewController@598535]
13:24:18,044 INFO [SimpleUrlHandlerMapping] Mapped URL path [/spring*.ftl] onto handler [org.springframework.web.servlet.mvc.ServletForwardingController@56eb62]
13:24:18,044 INFO [SimpleUrlHandlerMapping] Mapped URL path [/shared-resources/**] onto handler [org.springframework.web.servlet.mvc.ServletForwardingController@56eb62]
...
My BarController is of course catching all requests (like /spring_en_US.ftl), but I want it to be tried last. In other words, I want the SimpleUrlHandlerMapping to take priority over the DefaultAnnotationHandlerMappings in my application.
The best solution I found was to replace mvc:annotation-config with explicit DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter bean configuration. I was then able to set the order property on both SimpleUrlHandlerMapping (order = 0) and DefaultAnnotationHandlerMapping (order = 1). This set the priority of the handlers as I needed.
I tried to reorder mvc:annotation-config below SimpleUrlHandlerMapping, but it didn’t change the handler priority as needed.