Why can't I have the same controller name in another package with annotation configuration?

Jul 27, 2011 10:56:15 AM org.springframework.web.servlet.FrameworkServlet 
initServletBean

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: 

Unexpected exception parsing XML document from ServletContext resource
[/WEB-INF/dispatcher-servlet.xml]; 

nested exception is java.lang.IllegalStateException: 

Annotation-specified bean name 'fooController' for 
bean class [com.fooapp.ctrl.FooController] 
conflicts with existing, non-compatible bean definition of same name 
and class [com.fooapp.ctrl.admin.FooController]

In both packages, I defined the controller using annotation @Controller:

@Controller
public class FooController {
...

Should I use a different name for the controller in the package admin?

+5
source share
1 answer

By default, the bean -name for @Componentor derivative ( @Controller, @Serviceetc.) is an unqualified class name with a lower first character. To have these two controllers together, just set a different bean name (for at least one of them):

@Controller("secondFooController")

Check this section of the documentation.

+15
source

All Articles