Spring @bean冲突解决方案
生活随笔
收集整理的這篇文章主要介紹了
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冲突解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原神如何获取家具图纸?
- 下一篇: 不写容易出错的代码