Caused by: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix

huangapple go评论61阅读模式
英文:

Caused by: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix

问题

你的配置中出现了一个问题,应该是由于找不到名为 "Hystrix" 的 GatewayFilterFactory 导致的。你已经添加了相应的依赖项,但问题仍然存在。可能需要检查一下你的依赖版本是否与 Spring Cloud Gateway 版本兼容,或者确保你的应用正确引入了这些依赖项。另外,还可以尝试重新构建和部署你的应用程序,以确保依赖项已正确加载。

英文:

I have Spring Cloud Gateway 2021.0.8 with the following configuration:

spring:
  cloud:
    gateway:
      forwarded:
        enabled: false
      routes:
        - id: portal
          uri: lb://portal
          predicates:
            - Path=/client-portal/**
          filters:
            - name: Hystrix
              args:
                name: client-mobile-portal

But during startup I get error:

org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.27.jar:5.3.27]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:937) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64) ~[spring-boot-2.6.15.jar:2.6.15]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745) ~[spring-boot-2.6.15.jar:2.6.15]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:423) ~[spring-boot-2.6.15.jar:2.6.15]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.6.15.jar:2.6.15]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) ~[spring-boot-2.6.15.jar:2.6.15]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.6.15.jar:2.6.15]
at com.atlas.psp.gw.Application.main(Application.java:15) ~[main/:na]
Caused by: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix
at org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator.loadGatewayFilters(RouteDefinitionRouteLocator.java:131) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator.getFilters(RouteDefinitionRouteLocator.java:178) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator.convertToRoute(RouteDefinitionRouteLocator.java:118) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxFlatMap$FlatMapMain.tryEmitScalar(FluxFlatMap.java:489) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:422) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.drain(FluxMergeSequential.java:439) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.innerComplete(FluxMergeSequential.java:335) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialInner.onSubscribe(FluxMergeSequential.java:559) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:201) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:83) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.Flux.subscribe(Flux.java:8642) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.onNext(FluxMergeSequential.java:237) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:335) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:294) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.onSubscribe(FluxMergeSequential.java:198) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:201) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:83) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.Flux.subscribe(Flux.java:8642) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.onNext(FluxMergeSequential.java:237) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:335) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:294) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.onSubscribe(FluxMergeSequential.java:198) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:201) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:83) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.Flux.subscribe(Flux.java:8642) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.Flux.blockLast(Flux.java:2760) ~[reactor-core-3.4.29.jar:3.4.29]
at org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.lambda$onApplicationEvent$0(WeightCalculatorWebFilter.java:134) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.ifAvailable(DefaultListableBeanFactory.java:2046) ~[spring-beans-5.3.27.jar:5.3.27]
at org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.onApplicationEvent(WeightCalculatorWebFilter.java:134) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.cloud.gateway.route.RouteRefreshListener.reset(RouteRefreshListener.java:73) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at org.springframework.cloud.gateway.route.RouteRefreshListener.onApplicationEvent(RouteRefreshListener.java:54) ~[spring-cloud-gateway-server-3.1.8.jar:3.1.8]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.27.jar:5.3.27]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:85) ~[spring-cloud-netflix-eureka-client-3.1.7.jar:3.1.7]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.27.jar:5.3.27]
... 14 common frames omitted
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99) ~[reactor-core-3.4.29.jar:3.4.29]
at reactor.core.publisher.Flux.blockLast(Flux.java:2761) ~[reactor-core-3.4.29.jar:3.4.29]
... 31 common frames omitted

I added:

implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix:2.2.10.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'

But the issue is still present. Do you know how I can fix this?

答案1

得分: 1

  1. 访问 https://docs.spring.io/spring-cloud/docs/2021.0.8/reference/html/
  2. spring cloud 2021.0.8 -> spring-cloud-gateway 版本 3.1.8
  3. 访问 https://docs.spring.io/spring-cloud-gateway/docs/3.1.8/reference/html/#spring-cloud-circuitbreaker-filter-factory
  4. Hystrix GatewayFilter 工厂在 spring-cloud-gateway 3.1.8 中不受支持
  5. 访问 https://docs.spring.io/spring-cloud-gateway/docs/2.2.10.RELEASE/reference/html/#hystrix
  6. 但在 spring-cloud-gateway 2.2.10 中支持 Hystrix GatewayFilter 工厂
  7. 您可以使用 CircuitBreaker 替代 Hystrix 或更改 Spring Cloud 版本

以下是示例配置回退:

spring:
  cloud:
    gateway:
      routes:
        - id: portal
          uri: lb://portal
          predicates:
            - Path=/client-portal/**
          filters:
            - name: CircuitBreaker
              args:
                name: client-mobile-portal
                fallbackUri: forward:/clientPortalFallback
@RestController
public class FallbackController {

    @GetMapping("/clientPortalFallback")
    public Object fallback() {
        Map<String,Object> result = new HashMap<>();
        result.put("data",null);
        result.put("message","Get request fallback!");
        result.put("code",500);
        return result;
    }
}

(Note: The code sections were provided without translation as per your request.)

英文:
  1. visit https://docs.spring.io/spring-cloud/docs/2021.0.8/reference/html/

  2. spring cloud 2021.0.8 -> spring-cloud-gateway version 3.1.8

  3. visit https://docs.spring.io/spring-cloud-gateway/docs/3.1.8/reference/html/#spring-cloud-circuitbreaker-filter-factory

  4. Hystrix GatewayFilter Factory isn't supported in spring-cloud-gateway 3.1.8

  5. visit https://docs.spring.io/spring-cloud-gateway/docs/2.2.10.RELEASE/reference/html/#hystrix

  6. but Hystrix GatewayFilter Factory is supported in spring-cloud-gateway 2.2.10

  7. you can use CircuitBreaker instead of Hystrix or change spring cloud version

The following example configures such a fallback:

spring:
cloud:
gateway:
routes:
- id: portal
uri: lb://portal
predicates:
- Path=/client-portal/**
filters:
- name: CircuitBreaker
args:
name: client-mobile-portal
fallbackUri: forward:/clientPortalFallback
@RestController
public class FallbackController {

    @GetMapping(&quot;/clientPortalFallback&quot;)
    public Object fallback() {
        Map&lt;String,Object&gt; result = new HashMap&lt;&gt;();
        result.put(&quot;data&quot;,null);
        result.put(&quot;message&quot;,&quot;Get request fallback!&quot;);
        result.put(&quot;code&quot;,500);
        return result;
    }
}

huangapple
  • 本文由 发表于 2023年5月18日 00:00:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274039.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定