Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 视频教程 | 打赏(Donations) | About
知乎专栏多维度架构 微信号 netkiller-ebook | QQ群:128659835 请注明“读者”

第 10 章 WebFlux framework

目录

10.1. Getting Started
10.1.1. Maven
10.1.2. Application
10.1.3. RestController
10.1.4. 测试
10.2. WebFlux Router
10.2.1. Component 原件
10.2.2. 路由配置
10.2.3. Thymeleaf
10.2.3.1. 模板引擎 Thymeleaf 依赖
10.2.3.2. application.properties 相关的配置
10.2.3.3.
10.2.3.4. Tymeleaf 视图
10.2.4. Webflux Redis
10.2.4.1. Maven Redis 依赖
10.2.4.2. Redis 配置
10.2.4.3. Config
10.2.4.4. Service
10.2.4.5.
10.2.5. Webflux Mongdb
10.2.5.1. Maven 依赖
10.2.5.2. Repository
10.2.5.3. Service
10.2.5.4. 控制器
10.2.6. SSE
10.2.7. Mono/Flux

10.1. Getting Started

10.1.1. Maven

    		
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.1.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>cn.netkiller</groupId>
	<artifactId>webflux</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>webflux</name>
	<description>Demo webflux project for Spring Boot</description>

	<properties>
		<java.version>11</java.version>
	</properties>

	<dependencies>
		<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>
		<dependency>
			<groupId>org.springframework.restdocs</groupId>
			<artifactId>spring-restdocs-mockmvc</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
    		
    		
			

10.1.2. Application

    		
package cn.netkiller.webflux;

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);
	}

}
    		
    		
			

10.1.3. RestController

    		
package cn.netkiller.webflux;

import org.reactivestreams.Publisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Mono;

@RestController
public class TestController {

	public TestController() {

	}

	@GetMapping("/")
	@ResponseBody
	public Publisher<String> index() {
		return Mono.just("Hello world!");
	}

}
    		
    		
			

10.1.4. 测试

			
neo@MacBook-Pro ~/webflux % mvn spring-boot:run			
			
			
			
neo@MacBook-Pro ~ % curl http://localhost:8080
Hello world!%