【发布时间】:2019-07-03 11:11:40
【问题描述】:
我有一个RouterFunction,里面有嵌套的路由,除了一条路由之外的所有东西都在做我认为他们应该做的事情。
但是,当我尝试在嵌套路由中调用其中一个根路由时,我总是得到 404。这只发生在该特定路由上,当我将它从根更改为“/foo”时,它开始工作。
代码:
public RouterFunction<ServerResponse> productRouter(final ProductHandler handler) {
return nest(path(apiPath + BASE_PATH),
route(POST("/").and(contentType(MediaType.APPLICATION_JSON)), handler::handleCreateProduct)
.andRoute(GET("/{id}"), handler::handleGetProductById)
.andRoute(PUT("/").and(contentType(MediaType.APPLICATION_JSON)), handler::handleUpdateProduct)
.andRoute(GET("/"), handler::handleGetAllProducts)
.andNest(path("/category"),
route(POST("/").and(contentType(MediaType.APPLICATION_JSON)), handler::handleCreateProductCategory)
.andRoute(GET("/{id}"), handler::handleGetProductCategoryById)
.andRoute(GET("/"), handler::handleGetAllProductCategories)
.andRoute(GET("/search/{name}"), handler::handleGetProductCategoriesByName)
))
.andNest(path("/brand"),
route(POST("/").and(contentType(MediaType.APPLICATION_JSON)), handler::handleCreateProductBrand)
.andRoute(GET("/"), handler::handleGetAllProductBrands)
.andRoute(GET("/{id}"), handler::handleGetProductBrandById));
}
不正确的路线如下:
.andRoute(GET("/"), handler::handleGetAllProductCategories)
奇怪的是在根路径和品牌路径下我做完全相同的事情并且这些路径有效。
感谢您的帮助
【问题讨论】:
-
您能提供更多信息吗?
apiPath和BASE_PATH的值是什么? -
apiPath = "/api/v1" 和 BASE_PATH = "/products"
-
所以我发现“/api/v1/products/category/”返回 404,但是当我使用“/api/v1/products/category//”时它返回列表我我期待,我已经看到这是 github 上某个地方的错误,但似乎无法再次找到它,我正在使用 spring-boot 2.1.2 和 webflux 5.1.4
标签: spring spring-boot spring-webflux