首页 > 代码库 > Mingyang.net:org.springframework.context.annotation.ConflictingBeanDefinitionException
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{ ......}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。