0

I'm porting a large Spring 3.0 application to Spring 3.2 (yes, I know). The application combines XML and annotation configuration to define routes, for example:

servlet.xml:

<context:annotation-config/>
<context:component-scan base-package="foo.bar" />
...
<mvc:annotation-driven />
...
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    ...
    <property name="mappings">
        <props>
            <prop key="/booking/default.htm">booking.default</prop>
            ...
        </props>
    </property>
    ...
</bean>

<bean id="booking.default" class="foo.bar.BookingController">
    ...
</bean>

BookingController.java

@Controller
public class BookingController {
    ...
    @RequestMapping(method = RequestMethod.GET)
    public String handleRequest(...)
    ...
}

In Spring 3.0, the effect is to map GET /booking/default.htm to the handleRequest method of BookingController, however I have been unable to recreate this behaviour in Spring 3.2.

Spring 3.2, it seems, ignores the XML and views every method annotated with @RequestMapping(method = RequestMethod.GET) as the same, aborting on startup with java.lang.IllegalStateException: Ambiguous mapping found.

There are a large number of methods configured this way. Some of them have the @RequestMapping in a base library class that I can't change.

I can work around it by moving the url path from the XML configuration to the annotation, but I'd like to avoid that (for various reasons) and replicate the Spring 3.0 behaviour.

Is that possible? Searching for an answer has not been successful.

johngirvin
  • 611
  • 4
  • 12

1 Answers1

0

UPDATE:

TL;DR: This is not possible from Spring 3.1 onwards

Reading a SO "related questions" link: SpringMVC 3.0 to 3.1 migration of ControllerClassNameHandlerMapping

Led me to: http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html

Which contains the excerpt:

New Support Classes for @RequestMapping methods in Spring MVC 3.1

...

There are also several things no longer possible:

Select a controller first with a SimpleUrlHandlerMapping or BeanNameUrlHandlerMapping and then narrow the method based on @RequestMapping annotations.

Which explains my problem.

Community
  • 1
  • 1
johngirvin
  • 611
  • 4
  • 12