【问题标题】:spring-cloud-gateway RewritePath GatewayFilter not workingspring-cloud-gateway RewritePath GatewayFilter 不起作用
【发布时间】:2018-11-14 20:02:03
【问题描述】:

我正在开发一个 spring-cloud-gateway 应用程序。我在哪里使用 RewritePath GatewayFilter 来处理一些pathvariable。以下是我在 port 80 上运行的下游 api。

@GetMapping("/appname/event/{eventId}")
public Mono<ResponseEntity> getEventTimeOutWithPathVariable(
        @RequestHeader(name = "customerId") UUID customerId,
        @PathVariable(name = "eventId") String eventId) {
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("customerId", customerId);
    map.put("eventId", eventId);
    return Mono.just(new ResponseEntity(map, HttpStatus.OK));
}

在我的网关应用程序中,过滤器配置如下:

- id: api_timeout_route
  uri: http://localhost/appname/event/
  predicates:
  - Path=/withapitimeout/**
  filters:
  - Hystrix=apiTimeOut 
  - RewritePath=/withapitimeout/(?<segment>.*), /$\{segment}

但它不起作用。我做错了什么?我收到以下日志。

Mapping [Exchange: GET http://localhost:8000/withapitimeout/306ac5d0-b6d8-4f78-bde8-c470478ed1b1] 
to Route{id='api_timeout_route', uri=http://localhost:80/appname/event/

主要是路径变量没有被重写。有什么帮助吗?

【问题讨论】:

    标签: spring-boot spring-cloud spring-cloud-gateway


    【解决方案1】:

    我不是专家,但您可以尝试以下方法:

    - id: api_timeout_route
      uri: http://localhost
      predicates:
      - Path=/withapitimeout/**
      filters:
      - Hystrix=apiTimeOut 
      - RewritePath=/withapitimeout/(?<segment>.*), /appname/event/$\{segment}
    

    让我知道 ;)

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 2021-10-14
      • 2021-03-27
      • 2020-04-01
      • 2019-08-16
      • 2022-08-24
      • 2023-02-02
      • 2022-10-19
      • 2018-06-29
      相关资源
      最近更新 更多