Spring启动异常之ConflictingBeanDefinitionException: Annotation-specified bean name ‘XXXXXService‘

本文分析了一个Spring Boot项目启动时遇到的BeanDefinitionStoreException问题,该问题源于相同类名但不同包的 ReceiptService 类导致的冲突。解决方案是修改包名或删除其中一个Bean定义,并使用@Service注解的value属性进行重命名。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

项目启动报错信息如下:

Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.kungeek.cpp.fssc.MdataApplication]; 
nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: 
Annotation-specified bean name 'receiptService' for bean class
 [com.xxx.service.receipt.ReceiptService] conflicts with existing, non-compatible bean definition of same name and class 
 [com.xxx.service.budget.apply.accesory.ReceiptService]

原因分析:

提示:这里填写问题的分析:

spring IOC解析注解到bean池中,扫描到的类名相同但是不相同,就会出现上面错误。

看最后两行内容:

 [com.xxx.service.receipt.ReceiptService] 
 [com.xxx.service.budget.apply.ReceiptService]

解决方案:

  1. 修改包的名称,或者删除一个包
  2. @Service(value = “重命名”)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值