概述

什么是 Spring WebFlux, 它是一种异步的, 非阻塞的, 支持背压(Back pressure)机制的Web 开发框架. 要深入了解 Spring WebFlux, 首先要了知道 Reactive Stream, 和**命令式编程**相较而言, 只是另一种编程姿势.

滚床单的姿势有很多种, 目的都一样.

WebFlux 支持两种编程风(姿)格(势)

  • 使用@Controller这种基于注解的姿势, 与Sring MVC的姿势相同
  • 基于Java 8 Lambda的函数式编程风格

注意: 上面只是两种编程的姿势, 和"普通话和重庆话都是中国话"是一个道理. 我们公司也有外地的, 对他我说普通话, 对本地同事说重庆话. 这叫多态

创建项目

本文的源码在最下面

通过 http://start.spring.io 创建项目骨架.

oUCtFUkaJjAgcwha.png

如果是手工配置, 需要添加Spring的里程碑(Milestone)仓库:

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

测试

列举所有用户

19iG0tqFheiEo87T.png

创建用户

PK1JCefjubxfVrOU.png

获取单个用户

UV7bQKoZarLivIhl.png

修改

Yv8FkWoI61POE28g.png

删除

GCUCHDnjvWgdyrCc.png

源码

demo-spring-boot-webflux-annotaion

你可能感兴趣的内容
Spring Boot中使用 MongoDB 3.0 收藏,4163 浏览
0条评论
MI

Mitul-Maheshwari

这家伙太懒了,什么都没留下
Owner