关于通过ApplicationContext上下文无法获取到feignClient的类(2)

10 篇文章 0 订阅

关于通过ApplicationContext上下文无法获取到feignClient的类

我实在gateway网关服务做的处理

如果上述的方法无法获取到feignClient的类

报以下错:

No qualifying bean of type 'org.springframework.boot.autoconfigure.http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

feign.codec.EncodeException: No qualifying bean of type 'org.springframework.boot.autoconfigure.http.HttpMessageConverters' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方案:

在对应的服务新增配置


import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;

import java.util.stream.Collectors;

@Configuration
public class GatewayFeignConfig {
    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }
}

接着会发现又报另一个错误:

 block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3

因为gateway网关Feign调用微服务异常,spring boot 2.7.0 WebFlux必须使用异步调用,同步会报错

解决方案:

改为异步

{
    //异步调用
    CompletableFuture<Object> completableFuture = CompletableFuture.supplyAsync(() -> {
            return xxxFeign.method();
    });

    //从completableFuture中取出返回值即可
    XXXVo xxxVo = (XXXVo) completableFuture.get();
    
    //业务操作
    int xxx = xxxVo.getXXX();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值