解决Spring中ConflictingBeanDefinitionException: 冲突的Bean定义异常
"ConflictingBeanDefinitionException: Annotation-specified bean name 'toiletAppCountryReportController' for bean class [com.bonoon.toilet.app.controller.task.ToiletAppCountryReportController] conflicts with existing, non-compatible bean definition of same name and class [com.bonoon.toilet.app.controller.ToiletAppCountryReportController]" 错误通常发生在 Spring 容器中存在两个相同名称但不兼容的 bean 定义时。为了解决这个问题,你需要修改其中一个 bean 的名称或类名,使其在容器中具有唯一的标识。
解决方案
- 修改 bean 的名称: 将其中一个 bean 的名称在注解中修改为一个不同的名称,例如将
toiletAppCountryReportController修改为toiletAppTaskCountryReportController。
@Controller(\"toiletAppTaskCountryReportController\")
public class ToiletAppCountryReportController {
// ...
}
- 修改 bean 的类名: 将其中一个 bean 的类名修改为一个不同的类名,例如将
ToiletAppCountryReportController修改为ToiletAppTaskCountryReportController。
@Controller
public class ToiletAppTaskCountryReportController {
// ...
}
其他注意事项
- 如果使用了自动扫描的方式注册 bean,需要确保在类上使用了合适的注解(例如
@Component、@Service、@Controller等)。 - 如果通过 XML 配置的方式注册 bean,则需要相应修改 XML 配置文件中的 bean 定义。
完成以上的修改后,重新运行你的应用程序,这个错误应该就会解决了。
原文地址: https://www.cveoy.top/t/topic/pTKL 著作权归作者所有。请勿转载和采集!