Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not have the same Controller name in a different package with annotation-based 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 the @Controller annotation:

@Controller
public class FooController {
...

Do I have to use a different name for the Controller in the admin package?

like image 275
Ugor Avatar asked Jul 27 '11 10:07

Ugor


1 Answers

The default bean-name for a @Component or derivative (@Controller, @Service, etc.) is the unqualified class name with a lower first character. In order to have those two controllers together, just set a different bean name (for at least one of them):

@Controller("secondFooController")

Check this section of the documentation.

like image 85
Costi Ciudatu Avatar answered Nov 14 '22 22:11

Costi Ciudatu