From 9df27f3ca24d28e67eae46f3862256fa7f892986 Mon Sep 17 00:00:00 2001 From: ityouknow Date: Wed, 28 Dec 2022 17:41:43 +0800 Subject: [PATCH] add spring-boot-webflux --- README.md | 1 + spring-boot-webflux/pom.xml | 58 +++++++++++++++++++ .../main/java/com/neo/WebFluxApplication.java | 12 ++++ .../java/com/neo/web/HelloController.java | 14 +++++ .../src/main/resources/application.properties | 0 .../src/test/java/com/neo/HelloTests.java | 21 +++++++ .../java/com/neo/WebFluxApplicationTests.java | 16 +++++ 7 files changed, 122 insertions(+) create mode 100644 spring-boot-webflux/pom.xml create mode 100644 spring-boot-webflux/src/main/java/com/neo/WebFluxApplication.java create mode 100644 spring-boot-webflux/src/main/java/com/neo/web/HelloController.java create mode 100644 spring-boot-webflux/src/main/resources/application.properties create mode 100644 spring-boot-webflux/src/test/java/com/neo/HelloTests.java create mode 100644 spring-boot-webflux/src/test/java/com/neo/WebFluxApplicationTests.java diff --git a/README.md b/README.md index 3db1a9a..9e0a5fa 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Spring Boot 使用的各种示例,以最简单、最实用为标准,此开 - [spring-boot-banner](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-hello):Spring Boot 3.0 定制 banner 示例 - [spring-boot-helloworld](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-helloWorld):Spring Boot 3.0 Hello World Test 单元测试示例 - [spring-boot-web](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-web):Spring Boot 3.0 web 示例 +- [spring-boot-webflux](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-webflux):Spring Boot 3.0 响应式编程 WebFlux 使用案例 - [spring-boot-redis](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-redis):Spring Boot 3.0 Redis 示例 - [spring-boot-thymeleaf](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-thymeleaf):Spring Boot 3.0 Thymeleaf 语法、布局使用示例 - [spring-boot-jpa](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-jpa):Spring Boot 3.0 Jpa 操作、增删、改查多数据源使用示例 diff --git a/spring-boot-webflux/pom.xml b/spring-boot-webflux/pom.xml new file mode 100644 index 0000000..16b66ab --- /dev/null +++ b/spring-boot-webflux/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + com.neo + spring-boot-webflux + 1.0.0-SNAPSHOT + jar + + spring-boot-webflux + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 3.0.0 + + + + + UTF-8 + 17 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + test + + + org.hamcrest + hamcrest-core + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/spring-boot-webflux/src/main/java/com/neo/WebFluxApplication.java b/spring-boot-webflux/src/main/java/com/neo/WebFluxApplication.java new file mode 100644 index 0000000..b89527d --- /dev/null +++ b/spring-boot-webflux/src/main/java/com/neo/WebFluxApplication.java @@ -0,0 +1,12 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebFluxApplication { + + public static void main(String[] args) { + SpringApplication.run(WebFluxApplication.class, args); + } +} diff --git a/spring-boot-webflux/src/main/java/com/neo/web/HelloController.java b/spring-boot-webflux/src/main/java/com/neo/web/HelloController.java new file mode 100644 index 0000000..681a154 --- /dev/null +++ b/spring-boot-webflux/src/main/java/com/neo/web/HelloController.java @@ -0,0 +1,14 @@ +package com.neo.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +@RestController +public class HelloController { + + @GetMapping("/hello") + public Mono hello() { + return Mono.just("Welcome to reactive world ~"); + } +} diff --git a/spring-boot-webflux/src/main/resources/application.properties b/spring-boot-webflux/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/spring-boot-webflux/src/test/java/com/neo/HelloTests.java b/spring-boot-webflux/src/test/java/com/neo/HelloTests.java new file mode 100644 index 0000000..aa9389c --- /dev/null +++ b/spring-boot-webflux/src/test/java/com/neo/HelloTests.java @@ -0,0 +1,21 @@ +package com.neo; + +import com.neo.web.HelloController; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.reactive.server.WebTestClient; + +@RunWith(SpringRunner.class) +@WebFluxTest(controllers = HelloController.class) +public class HelloTests { + @Autowired + WebTestClient client; + + @Test + public void getHello() { + client.get().uri("/hello").exchange().expectStatus().isOk(); + } +} diff --git a/spring-boot-webflux/src/test/java/com/neo/WebFluxApplicationTests.java b/spring-boot-webflux/src/test/java/com/neo/WebFluxApplicationTests.java new file mode 100644 index 0000000..b7b4ed7 --- /dev/null +++ b/spring-boot-webflux/src/test/java/com/neo/WebFluxApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class WebFluxApplicationTests { + + @Test + public void contextLoads() { + } + +}