日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

feignClient注入失敗

作者:Json_Marz 更新時間: 2024-03-24 編程語言

新建的服務提供feign調用時,調用方無法注入提供方的feign。大致的報錯信息:

no qualifying bean of type available

調用方的啟動類注解

@ComponentScan({"com.plumelog","com.admin.**"})
@SpringBootApplication
public class AdminApplication {

提供方啟動類注解

@ComponentScan({"com.plumelog","com.push.service.**"})
@EnableFeignClients(basePackages = "com.**")
@SpringBootApplication
public class PushServiceApplication {

發現調用方沒有

@EnableFeignClients(basePackages = "com.**") 注解,于是調用方加上這個注解后,報其他錯誤:
***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'authentication-feign.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

大致意思是,已經存在這個bean了,是否配置?spring.main.allow-bean-definition-overriding=true

去覆蓋它,然后加上此配置后報其他的feign注入失敗。

報錯原因分析:

定位到authentication-feign,查看該服務在feign下提供了自動裝配,項目啟動時自動注入,如果調用方啟動類加上@EnableFeifnClients注解就會注入兩次bean,所以在調用方不需要@EnableFeifnClients注解。但是不配置自動裝配就要依賴@EnableFeifnClients注解,這就互相矛盾了。

@Configuration
@EnableFeignClients(basePackages = "com.authorization.client.feign")
@ComponentScan(basePackages = "com.authorization.client.feign")
public class ClientAutoConfiguration {

解決方案:在新服務的feign包下也加上自動裝配配置。

原文鏈接:https://blog.csdn.net/Json_Marz/article/details/127007277

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新