build(SpringDemo): 更新 Maven 依赖并移除部分代码

- 添加了 Spring Boot 安全、集成和 IP 相关依赖
- 移除了 SSEEmitter 类的实现
- 添加了 SwaggerConfig 类的配置
This commit is contained in:
whai 2024-11-24 11:06:37 +08:00
parent ba8baf0b9d
commit 0341ebc835
4 changed files with 113 additions and 56 deletions

View File

@ -30,7 +30,11 @@
<java.version>17</java.version> <java.version>17</java.version>
</properties> </properties>
<dependencies> <dependencies>
<!--security-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
@ -44,6 +48,23 @@
<version>5.0.0</version> <version>5.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ip</artifactId>
</dependency>
<!-- &lt;!&ndash; openAPI包替换 Swagger 的 SpringFox &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.springdoc</groupId>-->
<!-- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>-->
<!-- <version>2.2.0</version>-->
<!-- </dependency>-->
<!-- caffeine 缓存使用姿势 --> <!-- caffeine 缓存使用姿势 -->
<dependency> <dependency>
<groupId>com.github.ben-manes.caffeine</groupId> <groupId>com.github.ben-manes.caffeine</groupId>

View File

@ -0,0 +1,42 @@
//package cn.whaifree.springdemo.config;
//
//import io.swagger.v3.oas.models.ExternalDocumentation;
//import io.swagger.v3.oas.models.OpenAPI;
//import io.swagger.v3.oas.models.info.Info;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//
//import java.util.ArrayList;
//
///**
// * Created with IntelliJ IDEA.
// *
// * @author : 村雨遥
// * @version : 1.0
// * @project : springboot-swagger3-demo
// * @package : com.cunyu.springbootswagger3demo.config
// * @className : SwaggerConfig
// * @createTime : 2022/1/6 14:19
// * @email : 747731461@qq.com
// * @微信 : cunyu1024
// * @公众号 : 村雨遥
// * @网站 : https://cunyu1943.github.io
// * @description :
// */
//
//@Configuration
//public class SwaggerConfig {
// @Bean
// public OpenAPI openAPI() {
// return new OpenAPI()
// .info(new Info()
// .title("接口文档标题")
// .description("SpringBoot3 集成 Swagger3接口文档")
// .version("v1"))
// .externalDocs(new ExternalDocumentation()
// .description("项目API文档")
// .url("/"));
// }
//}

View File

@ -1,55 +1,49 @@
package cn.whaifree.springdemo.controller.SSE; //package cn.whaifree.springdemo.controller.SSE;
//
import cn.hutool.core.util.StrUtil; //import cn.hutool.core.util.StrUtil;
import org.springframework.http.MediaType; //import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; //import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; //import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController; //import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; //import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
//
import java.io.IOException; //import java.io.IOException;
import java.util.Map; //import java.util.Map;
//
/** ///**
* @version 1.0 // * @version 1.0
* @Author whai文海 // * @Author whai文海
* @Date 2024/10/22 21:44 // * @Date 2024/10/22 21:44
* @注释 // * @注释
*/ // */
@RestController //@RestController
public class SSEEmitter { //public class SSEEmitter {
//
public static void main(String[] args) { // Map<String, SseEmitter> sseEmitterMap = new java.util.HashMap<>();
int a = 127; //
byte c = (byte) a; // @GetMapping(value = "/sseStart", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
System.out.println(Integer.toBinaryString(c)); // public SseEmitter sse(String key) {
System.out.println(c); // System.out.println(key);
} // if (!sseEmitterMap.containsKey(key)) {
Map<String, SseEmitter> sseEmitterMap = new java.util.HashMap<>(); // SseEmitter sseEmitter = new SseEmitter();
// sseEmitterMap.put(key, sseEmitter);
@GetMapping(value = "/sseStart", produces = MediaType.TEXT_EVENT_STREAM_VALUE) // }
public SseEmitter sse(String key) { //
System.out.println(key); // return sseEmitterMap.get(key);
if (!sseEmitterMap.containsKey(key)) { // }
SseEmitter sseEmitter = new SseEmitter(); //
sseEmitterMap.put(key, sseEmitter); // @PostMapping("sendSSE")
} // public void send(String key, String message) {
// if (sseEmitterMap.containsKey(key)) {
return sseEmitterMap.get(key); // SseEmitter sseEmitter = sseEmitterMap.get(key);
} // try {
// System.out.println(StrUtil.format("send message to {}:{}", key, message));
@PostMapping("sendSSE") // sseEmitter.send(message);
public void send(String key, String message) { // } catch (IOException e) {
if (sseEmitterMap.containsKey(key)) { // e.printStackTrace();
SseEmitter sseEmitter = sseEmitterMap.get(key); // }
try { // }else {
System.out.println(StrUtil.format("send message to {}:{}", key, message)); // throw new IllegalArgumentException("No such key");
sseEmitter.send(message); // }
} catch (IOException e) { // }
e.printStackTrace(); //}
}
}else {
throw new IllegalArgumentException("No such key");
}
}
}

Binary file not shown.