码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-08-08 11:50:15      阅读:464      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   os   io   for   ar   

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,布布扣,bubuko.com

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

标签:style   blog   color   java   os   io   for   ar   

原文地址:http://www.cnblogs.com/eastson/p/3898653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!