- 在应用程序中添加以下依赖项:
org.springframework.boot
spring-boot-starter-webflux
- 在应用程序中添加以下示例代码:
@SpringBootApplication
public class WebfluxApplication {
public static void main(String[] args) {
SpringApplication.run(WebfluxApplication.class, args);
}
@Bean
public RouterFunction route() {
return RouterFunctions.route(RequestPredicates.GET("/hello"),
request -> ServerResponse.ok().body(Mono.just("Hello, World!"), String.class));
}
}
- 构建并打包应用程序:
mvn clean package
- 将jar文件上传到服务器上,然后使用以下命令运行应用程序:
java -jar webflux-example-0.0.1-SNAPSHOT.jar
- 访问http://localhost:8080/hello可以看到“Hello, World!”的响应。