zoukankan      html  css  js  c++  java
  • 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
    {
        ......
    }
  • 相关阅读:
    vue-cli3和element做一个简单的登陆页面
    用vue和layui简单写一个响应式数据展示表
    js中的AJAX
    js个人笔记简记
    解决sublime快捷键回车换行问题
    Sublime设置格式化代码快捷键ctrl+shift+r
    2020前端最新面试知识点汇总
    cookie,sessionstorage,localstorage区别
    linux/centos7安装mysql
    linux基本命令的操作
  • 原文地址:https://www.cnblogs.com/eastson/p/3898653.html
Copyright © 2011-2022 走看看