解决 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 {
......
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM