Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring云网关从路由返回404状态代码_Spring Boot_Spring Cloud Gateway - Fatal编程技术网

Spring boot Spring云网关从路由返回404状态代码

Spring boot Spring云网关从路由返回404状态代码,spring-boot,spring-cloud-gateway,Spring Boot,Spring Cloud Gateway,我想在任何路由返回404 HTTP代码时转到回退。原因是如果找不到资源,路由应该尝试从回退Uri获取该资源 下面是我定义的.yml。我试图实现的是,如果弹性搜索没有找到我的记录并返回404。在备用数据库中搜索。但我从网关得到404在这种情况下。有没有办法做到这一点 spring: application: name: gateway sleuth: sampler: probability: 1.0 cloud: gateway:

我想在任何路由返回404 HTTP代码时转到回退。原因是如果找不到资源,路由应该尝试从回退Uri获取该资源

下面是我定义的.yml。我试图实现的是,如果弹性搜索没有找到我的记录并返回404。在备用数据库中搜索。但我从网关得到404在这种情况下。有没有办法做到这一点

spring:
  application:
    name: gateway

  sleuth:
    sampler:
      probability: 1.0

  cloud:
    gateway:
      discovery:
        locator:
          enabled: true

        - id: search_route
          uri: lb://ELASTIC_SEARCH_SERVICE
          predicates:
            - Path=/unison/search/**
          filters:
            - name: Hystrix
              args:
                name: fallbackCommand
                fallbackUri: forward:/search/rdbms

您必须使用此命令使网关了解eureka服务器

eureka.client.service-url.defaultZone=http://user:pass@本地主机:8761/eureka

然后阻止网关注册到eureka

eureka.client.向eureka注册=false

第二个选项很重要,因为它使用lb:servicename结构导致404个负载平衡错误