I have an existing application in Sping 3.0 that uses ControllerClassNameHandlerMapping to map Controller and methods such as:
StartController.class is mapped to http://127.0.0.1/app/start/*
then
StartController.class has a method called init() that is mapped to http://127.0.0.1/app/start/init.html
Here is my configuration:
@Bean
public ControllerClassNameHandlerMapping classNameControllerMappings() {
return new ControllerClassNameHandlerMapping() {{
setCaseSensitive(true);
setDefaultHandler(new UrlFilenameViewController());
setInterceptors(new Object[]
{callProgressionInterceptorHandler(),
callSessionInterceptorHandler(),
localeChangeInterceptor()});
}};
}
Most of my controllers have 5-15 Request Mapped methods in each controller.
But when I upgrade to Spring 3.1+, the Request Mapping becomes ambiguous for each controller and is not mapped correctly.
I have read that one solution is to explicitely add the mthod name:
@RequestMapping(method = RequestMethod.GET)
Will now be:
@RequestMapping(method = RequestMethod.GET, value = "init")
I really do not want to manually add @RequestMapping value to 100+ methods if I dont have to.
Can anyone help with a better solution?
Here is the error I keep getting:
47672 [btpool0-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'addressConfirmationController' bean method
public void com.comcast.ivr.d2.web.controllers.AddressConfirmationController.houseNumber_rc(org.springframework.ui.ModelMap)
to {[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'addressConfirmationController' bean method
I also added setOrder(1); to ControllerClassNameHandlerMapping and still get this error.
UPDATE: I saw on http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html the following excerpt:
Prior to Spring 3.1, type and method-level request mappings were examined in two separate stages -- a controller was selected first by the DefaultAnnotationHandlerMapping and the actual method to invoke was narrowed down second by the AnnotationMethodHandlerAdapter.
With the new support classes in Spring 3.1, the RequestMappingHandlerMapping is the only place where a decision is made about which method should process the request. Think of controller methods as a collection of unique endpoints with mappings for each method derived from type and method-level @RequestMapping information.
Does this mean I cannot keep the same @RequestMapping without adding mapping details in the @RequestMapping as I did <3.1 ?
I have hundreds of methods that would need to be modified in order for this to happen... :-(