In my applicationContext.xml I have 2 beans with same class and different id(test and test1). The application context gets loaded correctly, but when I add @RequestMapping
to one method then the bean creation fails with the below error. This used to work with AnnotationMethodHandlerAdapter
but its failing with RequestMappingHandlerMapping
and RequestMappingHandlerAdapter
.
Error:
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 'test1' bean method
public java.lang.String com.test.render()
to {[/render],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'test' bean method
Please suggest how to fix this.
Code:
applicationContext.xml
<bean id="test" class="com.abc.test" />
<bean id="test1" class="com.abc.test" />
Controller
@Controller
@RequestMapping( value ={"/test/", "/test1/"})
public class test {
@RequestMapping("render")
public String render ()
{
//some code here.
}
}
I could find a work around with this. This solution if for the comments I posted on 21-May
I used order property to instantiate the custom defined RequestMappingHandlerMapping in the xml file and it worked!! It took my custom defined RequestMappingHandlerMapping instead of the default one loaded by
<annotation-driven>
.You can do it like this... switch from singleton approach to prototype and inside the xml do
While programmatically define
Would this approach do?