Mingyang.net:org.springframework.context.annotation.ConflictingBeanDefinitionException

org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name ‘configController‘ for bean class [net.mingyang.modules.system.ConfigController] conflicts with existing, non-compatible bean definition of same name and class [net.mingyang.cms.controller.ConfigController]
    org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:314)
    org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:253)
    org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:85)
    org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
    org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1424)
    org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1414)
    org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
    org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)
    org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    ... ...

问题的根源是我在两个不同的package里面定义两个ConfigController。默认的,Spring以类名作为Bean名,两个不同包里面的ConfigController就变成了相同的名字。

package net.mingyang.modules.system;

@Controller
@RequestMapping("/control/system/config")
public class ConfigController
{
    ......
}

//-----------------------------------------------------

package net.mingyang.cms.controller;

@Controller
@RequestMapping("/control/cms/config")
public class ConfigController
{
    ......
}

解决方法是为两个@Controller指定名字:

package net.mingyang.modules.system;

@Controller("/control/system/config")
@RequestMapping("/control/system/config")
public class ConfigController
{
    ......
}

//-----------------------------------------------------

package net.mingyang.cms.controller;

@Controller("/control/cms/config")
@RequestMapping("/control/cms/config")
public class ConfigController
{
    ......
}

Mingyang.net:org.springframework.context.annotation.ConflictingBeanDefinitionException,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。