相关疑难解决方法(0)

从zuul迁移到spring cloud gateway时如何“删除全局前缀('/api')然后转到lb://”

我想从 zuul 迁移到 spring 云网关,我不想更改我以前的应用程序的配置。我想知道如何处理带有“/api/ + 'serviceId'”的 url,路由到 lb://serviceId

之前的 zuul 配置

zuul: 
  prefix: /api
Run Code Online (Sandbox Code Playgroud)

eureka 有很多服务注册,我不想为每个服务注册一个路由。

例如。由 org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator 自动生成的路由

{
"route_id": "CompositeDiscoveryClient_APIGATEWAY",
"route_definition": {
  "id": "CompositeDiscoveryClient_APIGATEWAY",
  "predicates": [
    {
      "name": "Path",
      "args": {
        "pattern": "/apigateway/**"
      }
    }
  ],
  "filters": [
    {
      "name": "RewritePath",
      "args": {
        "regexp": "/apigateway/(?<remaining>.*)",
        "replacement": "/${remaining}"
      }
    }
  ],
  "uri": "lb://APIGATEWAY",
  "order": 0
}
Run Code Online (Sandbox Code Playgroud)

我想要的是

 {
"route_id": "CompositeDiscoveryClient_APIGATEWAY",
"route_definition": {
  "id": "CompositeDiscoveryClient_APIGATEWAY",
  "predicates": [
    {
      "name": "Path",
      "args": {
        "pattern": "/api/apigateway/**"
      }
    }
  ],
  "filters": [ …
Run Code Online (Sandbox Code Playgroud)

java spring-cloud netflix-zuul spring-cloud-gateway

1
推荐指数
1
解决办法
2486
查看次数