springCloudNetFlex hystrix 服务降级报错:FactoryBean threw exception on object creation;

这篇具有很好参考价值的文章主要介绍了springCloudNetFlex hystrix 服务降级报错:FactoryBean threw exception on object creation;。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

在做服务降级的时候,老是报错
先看一下具体错误:

FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.springCloudApi.service.testFallBackService found for feign client springCloudProvider

我是在api模块做的服务降级
springCloudApi

IServiceProvider

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
@FeignClient(name = "springCloudProvider", fallbackFactory = testFallBackService.class)
public interface IServiceProvider {

    @GetMapping("/listTest")
    List<testPO> listTest(@RequestParam("name") String name);

}

testFallBackService

import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class testFallBackService implements FallbackFactory<IServiceProvider> {

    @Override
    public IServiceProvider create(Throwable throwable) {
        return new IServiceProvider() {
            @Override
            public List<testPO> listTest(String name) {
                List<testPO> testPOS = new ArrayList<>();
                testPO testPO = new testPO();
                testPO.setName("该服务已被降级");
                testPOS.add(testPO);
                return testPOS;
            }
        };
    }
}

以上是服务降级的全部代码,然后我搜上面的报错,大部分都是在说我FallbackFactory类,没有加@Component这个注解,但我加了还是报这个错

 Error creating bean with name 'consumerController': Unsatisfied dependency expressed through field 'iServiceProvider'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.springCloudApi.service.IServiceProvider': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.springCloudApi.service.testFallBackService found for feign client springCloudProvider

我仔细看了这个错误,发现是我这个FallbackFactory类,没有注入到spring中所以它连带着IServiceProvider没有创建bean成功。
我沿着这个方向去搜索错误,被我找到了一个博主和我一样的问题。
感谢这位博主写的博客
https://blog.csdn.net/sdp1103285470/article/details/89084880
最终在你的springCloudConsumer模块的启动类中的@SpringBootApplication注解里面加上scanBasePackages问题就解决了,原因就是没有扫描到那个类嘛,那我们给他加上就好了,@EnableFeignClients中的basePackages只能扫描到Feign的注解。
以下是代码:

@EnableEurekaClient
@EnableFeignClients(basePackages = "com.springCloudApi")
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}, scanBasePackages = {"com.springCloudApi.service", "com.springCloudConsumerFeiger"})
public class consumerFeignApplication {
    public static void main(String[] args) {
        SpringApplication.run(consumerFeignApplication.class, args);
    }
}

注意:com.springCloudApi.service是包含FallbackFactory类的包(backage)。com.springCloudConsumerFeiger是你原本这个类的包扫描路径。如果你只加上com.springCloudApi.service那么你这个原本的扫描路径就会被覆盖掉。文章来源地址https://www.toymoban.com/news/detail-633150.html

到了这里,关于springCloudNetFlex hystrix 服务降级报错:FactoryBean threw exception on object creation;的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • SpringCloud-Hystrix服务熔断与降级工作原理&源码

    在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用。为了保证其高可用,单个服务通常会集群部署。由于网络原因或者自身的原因,服务并不能保证100%可用,如果单个服务出现问题,调用这

    2024年02月14日
    浏览(44)
  • springcloud3 hystrix实现服务降级的案例配置2

    \\\"服务器忙,请稍后在试\\\"不让客户达等待,立即返回一个友好的提示。 1.程序运行异常; 2.超时; 3.服务熔断触发服务降级; 4.线程池/信号量打满也会导致服务降级 2.1.1 pom文件 2.1.2 设置降级规则 代码  2.1.3 开启hystrix熔断 添加:@EnableHystrix 注解 2.2.1 pom文件 2.2.2 设置降级规

    2024年02月12日
    浏览(29)
  • Spring Cloud 容错机试 Hystrix 服务降级 RestTemplate:

    雪崩效应:   如果短信服务炸了后面的所有服务就会起连锁反应造成全部服务挂掉 , 这就是雪崩效应 , 那么其实短信服务又不是我们主要业务 , 这个时候我们可以采用服务降级 , 服务降级就是暂时的把短信服务停掉能用就返回不能用就返回个错误 , 但是它也不会影响

    2024年02月07日
    浏览(33)
  • OpenFegin+hystrix实现远程HTTP服务调用、服务降级(深度解析~保姆级)

    OpenFeign 是 Spring Cloud 家族的一个成员, 它最核心的作用是为 HTTP 形式的 Rest API 提供了非常简洁高效的 RPC 调用方式。支持Hystrix 、Ribbon和SpringMVC 注解。 Feign和OpenFeign的区别? 1、Feign: Feign是Netflix公司(第一代SpringCloud)研发的一个轻量级RESTful的伪HTTP服务客户端。 Feign内置了

    2023年04月08日
    浏览(29)
  • 云原生微服务 Spring Cloud Hystrix 降级、熔断实战应用

    第一章 Java线程池技术应用 第二章 CountDownLatch和Semaphone的应用 第三章 Spring Cloud 简介 第四章 Spring Cloud Netflix 之 Eureka 第五章 Spring Cloud Netflix 之 Ribbon 第六章 Spring Cloud 之 OpenFeign 第七章 Spring Cloud 之 GateWay 第八章 Spring Cloud Netflix 之 Hystrix 多个微服务之间调用的时候,假如微服

    2024年02月08日
    浏览(31)
  • (一)Spring Cloud 直击微服务作用、架构应用、hystrix降级

    直击微服务作用     遇到了什么问题?         将单体架构拆分成微服务架构后,如果保证多个服务(项目)正常运行?     哪个技术可以解决这个问题?         微服务技术         服务治理: 服务管理,维护服务与服务之间的关系     这个技术如何使用?         netflix/网飞:

    2024年02月03日
    浏览(32)
  • springboot整合feign实现RPC调用,并通过Hystrix实现服务降级

    feign/openfeign和dubbo是常用的微服务RPC框架,由于feigin内部已经集成ribbon,自带了负载均衡的功能,当有多个同名的服务注册到注册中心时,会根据ribbon默认的负载均衡算法将请求分配到不同的服务。这篇文章就简单介绍一下怎么使用feign来调用远程的服务。 首先,需要有一个

    2024年02月16日
    浏览(36)
  • SpringCloud-Hystrix服务熔断与降级工作原理&源码 | 京东物流技术团队

    在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用。为了保证其高可用,单个服务通常会集群部署。由于网络原因或者自身的原因,服务并不能保证100%可用,如果单个服务出现问题,调用这

    2024年02月14日
    浏览(31)
  • 微服务springcloud 06.feign框架,配合ribbon 负载均衡和重试,配合hystrix 降级,监控和熔断测试

    feign是ribbon +hystrix 的整合 01.新建 sp09-feign 项目 第一步: 第二步:选择依赖: pom.xml 需要添加 sp01-commons 依赖: 第三步:修改sp09-feign项目的application.yml 第四步:sp09-feign的主程序添加 @EnableDiscoveryClient 和 @EnableFeignClients 02.feign 声明式客户端 第一步:声明三个代理接口 这里的

    2024年02月10日
    浏览(40)
  • Dubbo hystrix 熔断降级 示例

    目录 Pom 应用启动类 接口 服务提供者 消费者 总结 因为jar包冲突问题报错 java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Object;)V 解决方式修改低版本springboot 改成如下 版本对照 全代码 pom 启动 实现 yml 有需要加上这个 有超时熔断跳转到 reliable

    2024年02月12日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包