spring-boot-webflux 基本使用

pom引入依赖

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

代码

复制代码
package org.qx.web.router;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RequestPredicates;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;

import static org.springframework.web.servlet.function.EntityResponse.fromObject;
import static org.springframework.web.servlet.function.ServerResponse.ok;

@Configuration
public class MyRouters {
    @Bean
    public RouterFunction<ServerResponse> helloRoutesV1() {
        return RouterFunctions.route(RequestPredicates.path("/v1/hello-world"),
                request -> ok().body(fromObject("Hello World v1!")));
    }

    @Bean
    public RouterFunction<ServerResponse> helloRoutesV2() {
        return RouterFunctions.route(RequestPredicates.path("/v2/hello-world"),
                request -> ok().body(fromObject("Hello World v2!!!")));
    }

}
复制代码

异常情况

Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider

解决:

引入pom依赖

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
</dependency>

 

解析:

其实用的是routerFunctionMapping 去进行路由解析的

 

posted @   浅笑19  阅读(540)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示