• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

feignClient注入失败

武飞扬头像
Json_Marz
帮助1

新建的服务提供feign调用时,调用方无法注入提供方的feign。大致的报错信息:

no qualifying bean of type available

调用方的启动类注解

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

提供方启动类注解

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

发现调用方没有

@EnableFeignClients(basePackages = "com.**") 注解,于是调用方加上这个注解后,报其他错误:
  1.  
    ***************************
  2.  
    APPLICATION FAILED TO START
  3.  
    ***************************
  4.  
     
  5.  
    Description:
  6.  
     
  7.  
    The bean 'authentication-feign.FeignClientSpecification' could not be registered. A bean with that name has already been defined and overriding is disabled.
  8.  
     
  9.  
    Action:
  10.  
     
  11.  
    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注解,这就互相矛盾了。

学新通

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

解决方案:在新服务的feign包下也加上自动装配配置。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgaecbj
系列文章
更多 icon
同类精品
更多 icon
继续加载