Spring Web Flux(反应式)功能路由与Kotlin无法正常工作

你好有兴趣在Kotlin编写Spring应用程序的人。 我正在玩Spring Boot 2.0.0快照和spring-webflux 。 这段代码:

 @Component class TestRouter() : RouterFunction<ServerResponse> { override fun route(request: ServerRequest) = route(request) { "/".route { GET("/hello") { ServerResponse.ok().body(BodyInserters.fromObject("World")) } "/{id}".route { GET("/hello") { ServerResponse.ok().body(BodyInserters.fromObject("World ${request.pathVariable("id")}")) } } } } } 

不按预期工作(至少如我所料:))

 ➜ ~ curl -i http://localhost:8080/hello HTTP/1.1 200 OK transfer-encoding: chunked Content-Type: text/plain;charset=UTF-8 World 

但:

 ➜ ~ curl -i http://localhost:8080/1/hello HTTP/1.1 404 Not Found content-length: 0 

工作案例跟踪:

 2017-03-03 00:58:03.865 TRACE 7666 --- [ctor-http-nio-4] oswrfserver.RequestPredicates : Pattern "//**" matches against value "/hello" 2017-03-03 00:58:03.865 DEBUG 7666 --- [ctor-http-nio-4] oswrfunction.server.RouterFunctions : Nested predicate "//**" matches against "GET /hello" 2017-03-03 00:58:03.865 TRACE 7666 --- [ctor-http-nio-4] oswrfserver.RequestPredicates : Method "GET" matches against value "GET" 2017-03-03 00:58:03.866 TRACE 7666 --- [ctor-http-nio-4] oswrfserver.RequestPredicates : Pattern "/hello" matches against value "/hello" 2017-03-03 00:58:03.866 DEBUG 7666 --- [ctor-http-nio-4] oswrfunction.server.RouterFunctions : Predicate "(GET && /hello)" matches against "GET /hello" 

不工作情况跟踪:

 2017-03-03 00:59:26.958 TRACE 7666 --- [ctor-http-nio-1] oswrfserver.RequestPredicates : Pattern "//**" matches against value "/1/hello" 2017-03-03 00:59:26.958 DEBUG 7666 --- [ctor-http-nio-1] oswrfunction.server.RouterFunctions : Nested predicate "//**" matches against "GET /1/hello" 2017-03-03 00:59:26.958 TRACE 7666 --- [ctor-http-nio-1] oswrfserver.RequestPredicates : Method "GET" matches against value "GET" 2017-03-03 00:59:26.958 TRACE 7666 --- [ctor-http-nio-1] oswrfserver.RequestPredicates : Pattern "/hello" does not match against value "/1/hello" 2017-03-03 00:59:26.959 TRACE 7666 --- [ctor-http-nio-1] oswrfserver.RequestPredicates : Pattern "/{id}/**" matches against value "/1/hello" 2017-03-03 00:59:26.959 DEBUG 7666 --- [ctor-http-nio-1] oswrfunction.server.RouterFunctions : Nested predicate "/{id}/**" matches against "GET /1/hello" 2017-03-03 00:59:26.959 TRACE 7666 --- [ctor-http-nio-1] oswrfserver.RequestPredicates : Method "GET" matches against value "GET" 2017-03-03 00:59:26.959 TRACE 7666 --- [ctor-http-nio-1] oswrfserver.RequestPredicates : Pattern "/hello" does not match against value "/1/hello" 

这看起来像一个错误(因为"/{id}".route {...}据说是使用RouterFunctions.nest),但我可能是错的。 您的想法和帮助是受欢迎的。

我明显知道我可以通过编写GET("/{id}/hello") { ... }来完成/1/hello工作,但是我对嵌套的.route { ...}变体感兴趣我从另一个位置(如地图等)添加嵌套路线的用例。