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.
}
}