zoukankan      html  css  js  c++  java
  • Spring Feign 注入失败问题排查思路

    Spring Feign 注入失败问题排查思路

    问题的表现很明显,就是在spring容器中找不到被@FeignClient标注类的实例:

    ***************************
    APPLICATION FAILED TO START
    ***************************
     
    Description:
     
    Field xxxClient in xxx包 required a bean of type 'xxxClient' that could not be found.
     
     
    Action:
    Consider defining a bean of type 'xxxClient' in your configuration.
    

    造成上述异常的原因很明显,在spring容器中找不到对应的实例。

    被@FeignClient标注的类,在容器初始化的时候会生成对应的代理的,如果没有生成,说明spring没有扫描到该类。所以在启动类上加上 @EnableFeignClients 即可。

    但有的情况下,只加@EnableFeignClients也是扫描不到的,比如说,你的项目是多模块,包名不同,所以扫描不到,这样可以在注解中指定 basePackages:

    @EnableFeignClients(basePackages = "xxx.proxy")
    public class xxxApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(xxxApplicationn.class, args);
        }
    }
    

    意思是扫描指定包路径下的 带有 @FeignClient 的类。

    如果你的 @EnableFeignClients 飘红引用不到,那你一定是引用错包了,对于SpringBoot这边建议引用starter:

    <!--    feign    -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    
  • 相关阅读:
    java网络爬虫爬虫小栗子
    浮点数精确表示
    使用yum安装CDH Hadoop集群
    判断奇数,java陷阱
    Long型整数,缄默溢出
    java基础知识点
    java常用指令
    Codeforces Round #275 (Div. 2) D
    区间dp的感悟
    Codeforces Round #386 (Div. 2) C D E G
  • 原文地址:https://www.cnblogs.com/keeya/p/14476548.html
Copyright © 2011-2022 走看看