为什么在具有基于注释的配置的其他程序包中不能具有相同的Controller名称? [英] Why can I not have the same Controller name in a different package with annotation-based configuration?
本文介绍了为什么在具有基于注释的配置的其他程序包中不能具有相同的Controller名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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]
在两个软件包中,我都使用@Controller
注释定义了控制器:
In both packages I defined the Controller using the @Controller
annotation:
@Controller
public class FooController {
...
在admin
程序包中,控制器是否必须使用其他名称?
Do I have to use a different name for the Controller in the admin
package?
推荐答案
@Component
或派生类(@Controller
,@Service
等)的默认bean名是不合格的类名,其首位较低特点.为了将这两个控制器放在一起,只需设置一个不同的Bean名称(至少为其中一个):
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")
检查 查看全文