Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException问题处理

问题

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.macro.mall.portal.MallPortalApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'globalExceptionHandler' for bean class [com.macro.mall.common.exception.GlobalExceptionHandler] conflicts with existing, non-compatible bean definition of same name and class [com.qike.common.exception.GlobalExceptionHandler]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203)
	at com.macro.mall.portal.MallPortalApplication.main(MallPortalApplication.java:24)
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'globalExceptionHandler' for bean class [com.macro.mall.common.exception.GlobalExceptionHandler] conflicts with existing, non-compatible bean definition of same name and class [com.qike.common.exception.GlobalExceptionHandler]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:348)
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:286)
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
	... 13 common frames omitted

主要问题提取:

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'globalExceptionHandler' for bean class [com.macro.mall.common.exception.GlobalExceptionHandler] conflicts with existing, non-compatible bean definition of same name and class [com.qike.common.exception.GlobalExceptionHandler]

原因

因为spring容器初始化同名不同包的类时,不知道加载哪一个,而导致的冲突。

处理

找到两个文件,去掉一个
com.macro.mall.common.exception.GlobalExceptionHandler
com.qike.common.exception.GlobalExceptionHandler

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException报错是由于存在重复的bean定义***com.compass.core.hanlder.BaseExceptionHandle]不兼容。这个错误通常发生在Spring Boot项目启动时,当存在相同名称但不兼容的bean定义时会触发该异常。 为解决这个问题,可以考虑以下方法: 1.检查项目中的bean定义,确保没有重复的名称或类。可以使用IDE的搜索功能来查找所有包含问题bean名称的地方。 2.如果确实存在相同名称但不兼容的bean定义,可以通过更改bean名称或类名来解决冲突。 3.另外,你也可以使用@ComponentScan注解的excludeFilters属性来排除掉不需要的bean定义,或者使用includeFilters属性来只包含需要的bean定义。这样可以更精确地控制项目中的bean扫描。 综上所述,Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException报错是由于存在重复的bean定义导致的。解决这个问题的方法包括检查重复的bean定义并进行修正,以及使用@ComponentScan注解的excludeFilters和includeFilters属性进行精确控制。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException Annotation 报错...](https://blog.csdn.net/weixin_42717648/article/details/128582047)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值