java - 如何通过 RouterFunctionMapping 在 Spring 5 webflux 中注册多个 RouterFunction?

标签 java spring kotlin

基于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/

相关文章:

java - 将现有的 WAR 添加到嵌入式 tomcat

android - Jetpack Compose : When using Modifier. selectable 如何防止可组合布局在滚动时被选择?

kotlin - Corda-IOU演示在Windows上不起作用

android - 房间数据库 : Still getting "no value passed for parameter ' id' "even though it is meant to be autogenerated

java - 如何并行化 Ants signJar 任务

java - swt 树查看器中的 Html

java - 如何在 Spring 中将 JdbcTemplate 转换为 Flux?

java - java中有没有办法创建全局变量?

java - 如何比较两个整数?

java - 使用 FileSystemXmlApplicationContext 编译 Spring Application 时出现 NoSuchMethodError