Spring Cloud Gateway RouteLocator Java代码无法通过特定的路由ID获取

时间:2019-07-07 03:10:48

标签: spring spring-cloud-gateway

我尝试使用Java代码在Spring Cloud Gateway中自定义RouteLocator。我可以看到在端点/ actuator / gateway / routes中注册的所有路由列表,但是当我尝试获取给定ID中的特定路由时,它是404 / actuator / gateway / routes / auth-server。

这就是我试图调用/ actuator / gateway / routes

的目的
[
    {
        "route_id": "auth-server",
        "route_object": {
            "predicate": "org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$264/896945135@4e9d7b14"
        },
        "order": 0
    },
    {
        "route_id": "song",
        "route_object": {
            "predicate": "org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$264/896945135@7d49ff95"
        },
        "order": 0
    }
]

具有特定路由/ actuator / gateway / routes / auth-server的那个

http://localhost:8080/actuator/gateway/routes/auth-server

我未找到结果状态代码404

这是java自定义路由配置:

@Configuration
public class RouteConfiguration {


    @Bean
        RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {

        return routeLocatorBuilder.routes()
                .route("auth-server", predicateSpec -> predicateSpec.path("/uaa/**").uri("lb://auth-service"))
                .route("song", predicateSpec -> predicateSpec.path("/song/**").uri("lb/song-service"))
                .build();
    }

}

它应该与auth-server路由一起提供。

1 个答案:

答案 0 :(得分:0)

@soyphea这是一个已知问题,但我在GitHub上找不到该票证。您是否可以为此确定一个错误报告:https://github.com/spring-cloud/spring-cloud-gateway/issues/new?谢谢您的提问!