Spring @bean冲突解决方案
Posted 21aspnet
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring @bean冲突解决方案相关的知识,希望对你有一定的参考价值。
引用2个jar都实现了相同的@bean注入,这个是feign的Level
@Bean
public Level feignLoggerLevel()
return Level.FULL;
这样报错:
escription:
xxx required a single bean, but 2 were found:
- feignLoggerLevel: defined by method 'feignLoggerLevel' in class path resource [com/xxx.class]
- logger: defined by method 'logger' in class path resource
[com/yyy.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
解决办法:
@Bean
@ConditionalOnMissingBean(Logger.Level.class)
public Level feignLoggerLevel()
return Level.FULL;
以上是关于Spring @bean冲突解决方案的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot requestDataValueProcessor Bean 定义冲突
Spring Boot 应用程序“bean 类的 bean 名称与现有冲突” - 如何从 3rd 方库/依赖项中排除包/类?
为什么两个不同的工程,启动tomcat时会报命名spring bean命名冲突的错误---两个不同的项目用到同一个action