SpringWeb Flux入门

发布时间 2023-05-06 14:21:46作者: shigp1

新建项目,加入依赖:

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


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>

SpringBoot版本选择2.7.9。

增加Controller:

@RestController
@RequestMapping("/flux")
public class MyController {

    @RequestMapping("/hello")
    public Mono<String> hello() {
        return Mono.just("Flux");
    }
}

访问http://localhost:8080/flux/hello,看到Flux。查看控制台看到:

 

 

看到Spring Flux 使用Netty作为容器。