基于webflux文档,可以使用RouterFunctionMapping扫描RouterFunctions:
RouterFunctionMapping — detects one or more RouterFunction beans in the Spring configuration, combines them via RouterFunction.andOther, and routes requests to the resulting composed RouterFunction.
是否有注册处理程序的好示例?
最佳答案
只需创建任意数量的 RouterFunction beans:
@Configuration
public class RoutesConfig {
@Bean
public RouterFunction helloRoutesV1() {
return RouterFunctions.route(RequestPredicates.path("/v1/hello-world"),
request -> ok().body(fromObject("Hello World v1!")));
}
@Bean
public RouterFunction helloRoutesV2() {
return RouterFunctions.route(RequestPredicates.path("/v2/hello-world"),
request -> ok().body(fromObject("Hello World v2!!!")));
}
}
关于java - 如何通过 RouterFunctionMapping 在 Spring 5 webflux 中注册多个 RouterFunction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49049383/