spring-boot-webflux 基本使用
pom引入依赖
org.springframework.boot spring-boot-starter-webflux
代码
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 RouterFunctionhelloRoutesV1() { 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!!!"))); } }
异常情况
Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider
解决:
引入pom依赖
io.netty netty-all
解析:
其实用的是routerFunctionMapping 去进行路由解析的