提交 b5f25e57 编写于 作者: C chengshiping

【WEB篇】Spring Boot 整合 Webflux

上级 43cdd6dc
......@@ -31,7 +31,7 @@
## WEB篇
- 【WEB篇】Spring Boot 利用 Webflux 提升吞吐量和伸缩性;
- [【WEB篇】Spring Boot 整合 Webflux](https://blog.csdn.net/csp732171109/article/details/124322939) `mingyue-springboot-webflux`
- 【WEB篇】Spring Boot 整合 WebSocket 推送与接受消息;
## 日志篇
......
<?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 https://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.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.csp</groupId>
<artifactId>mingyue-springboot-webflux</artifactId>
<version>1.0</version>
<name>mingyue-springboot-webflux</name>
<description>mingyue-springboot-webflux</description>
<properties>
<java.version>1.8</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-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- hutool 工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.csp.mingyue.webflux;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MingYueSpringbootWebfluxApplication {
public static void main(String[] args) {
SpringApplication.run(MingYueSpringbootWebfluxApplication.class, args);
}
}
package com.csp.mingyue.webflux.controller;
import com.csp.mingyue.webflux.model.MingYueUser;
import com.csp.mingyue.webflux.service.MingYueUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
/** @author Strive */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class MingYueUserController {
private final MingYueUserService mingYueUserService;
@GetMapping("/{userId}")
public Mono<MingYueUser> queryUserById(@PathVariable Long userId) {
return Mono.just(mingYueUserService.queryUserById(userId));
}
}
package com.csp.mingyue.webflux.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/** @author Strive */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MingYueUser {
private Long userId;
private String username;
}
package com.csp.mingyue.webflux.service;
import cn.hutool.core.map.MapUtil;
import com.csp.mingyue.webflux.model.MingYueUser;
import java.util.Map;
import org.springframework.stereotype.Service;
/** @author Strive */
@Service
public class MingYueUserService {
/** 模拟用户存储 */
private static final Map<Long, MingYueUser> USER_MAP = MapUtil.newHashMap();
static {
USER_MAP.put(1L, MingYueUser.builder().userId(1L).username("mingyue").build());
}
/**
* 根据用户ID查询用户信息
*
* @param userId 用户ID
* @return 用户信息
*/
public MingYueUser queryUserById(Long userId) {
return USER_MAP.get(userId);
}
}
app:
author: Strive
\ No newline at end of file
To My Love!
-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-
__ __ __ __
.*. /~ .~\ /~ ~\ /~ .~\ /~ ~\
*** ' `\/' * ' `\/' *
V ( .*)( . *)
/\|/\ \ Ming . *./ \ Yue . *./
| `\ . . .*/' `\ . . .*/' .*.
| `\ * .*. */' _ _ `\ * .*. */' ***
`\ * */' ( `\/'*) `\ * */' V
`\/' \ */' `\/' /\|/\
`\/' |
--+++==##<<{{******** Ming Yue ********}}>>##==++--
:: Spring Boot :: (${spring-boot.version})
--by ${app.author}
\ No newline at end of file
......@@ -52,6 +52,7 @@
<module>mingyue-springboot-mybatis-plus</module>
<module>mingyue-springboot-redis</module>
<module>mingyue-springboot-cache</module>
<module>mingyue-springboot-webflux</module>
</modules>
<build>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册