随笔 - 120  文章 - 0  评论 - 22  阅读 - 56万

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

 

posted on   欢跳的心  阅读(19981)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示