• 解决 org.springframework.context.annotation.ConflictingBeanDefinitionException


    Java web 项目启动时报错

    报错信息:

    Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'testService' for bean class [test.service.impl.TestServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [test.service.impl.TestService]

    通过搜索定位到是以下代码片段造成的报错。

    代码片段:

    代码1.ITestService 的实现类代码:
    @Service("testService")
    public class TestServiceImpl implements ITestService {
    ......
    }
    
    代码2.在Controller中使用代码:
    @Autowired
    private ITestService testService;

     代码 1 和 代码2 中的 testService 冲突了,项目启动时编译器检测到有两个相同名称的bean就会报错。

    解决方法:

    修改代码1和代码2中任意一个的名字即可解决

    例如:修改代码1中的名字

    1.ITestService 的实现类代码:
    @Service("testServiceImpl")
    public class TestServiceImpl implements ITestService {
    ......
    }
  • 相关阅读:
    Model、ModelMap和ModelAndView的使用详解
    maven的pom.xml配置json依赖
    int和Integer的区别
    SSM 视频
    2018-1-25 PHP数组
    2018-1-25 PHP函数方法
    2018-1-22 PHP 变量和常量
    2018-1-21 复习
    2018-1-18 如何用html和css实现div的缓慢移动效果
    2018-1-17 js弹出div登录窗口
  • 原文地址:https://www.cnblogs.com/etangyushan/p/13753942.html
Copyright © 2020-2023  润新知