1、依赖升级:springboot 2.7.18 -> 3.4.5,springcloud 2021.x -> 2024.x ,其余包同步yudao升级;2、微服务配置简化;

This commit is contained in:
gaoqr
2025-07-22 11:39:54 +08:00
parent 799affcecb
commit 20085ffb9f
915 changed files with 3116 additions and 4561 deletions
-11
View File
@@ -15,12 +15,6 @@
<description>API 服务网关,基于 Spring Cloud Gateway 实现</description>
<dependencies>
<!-- Spring Cloud 基础 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>com.cf.imes</groupId>
@@ -40,11 +34,6 @@
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId> <!-- 接口文档 -->
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
@@ -23,6 +23,7 @@ import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ReactiveHttpOutputMessage;
import org.springframework.http.codec.CodecConfigurer;
@@ -38,7 +39,7 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;
@@ -142,7 +143,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
AccessLog gatewayLog = new AccessLog();
gatewayLog.setRoute(WebFrameworkUtils.getGatewayRoute(exchange));
gatewayLog.setSchema(request.getURI().getScheme());
gatewayLog.setRequestMethod(request.getMethodValue());
gatewayLog.setRequestMethod(request.getMethod().name());
gatewayLog.setRequestUrl(request.getURI().getRawPath());
gatewayLog.setQueryParams(request.getQueryParams());
gatewayLog.setRequestHeaders(request.getHeaders());
@@ -220,7 +221,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
// 设置其它字段
gatewayLog.setUserId(SecurityFrameworkUtils.getLoginUserId(exchange));
gatewayLog.setResponseHeaders(response.getHeaders());
gatewayLog.setHttpStatus(response.getStatusCode());
gatewayLog.setHttpStatus((HttpStatus) response.getStatusCode());
// 获取响应类型,如果是 json 就打印
String originalResponseContentType = exchange.getAttribute(ServerWebExchangeUtils.ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR);
@@ -59,7 +59,7 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler {
// TODO 晨丰:这里要精细化翻译,默认返回用户是看不懂的
ServerHttpRequest request = exchange.getRequest();
log.error("[responseStatusExceptionHandler][uri({}/{}) 发生异常]", request.getURI(), request.getMethod(), ex);
return CommonResult.error(ex.getRawStatusCode(), ex.getReason());
return CommonResult.error(ex.getStatusCode().value(), ex.getReason());
}
/**
@@ -0,0 +1,21 @@
--- #################### 注册中心 + 配置中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: 192.168.1.205:8848 # Nacos 服务器地址
username: # Nacos 账号
password: # Nacos 密码
discovery: # 【配置中心】配置项
namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
config: # 【注册中心】配置项
namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
chenfeng:
gateway:
accessLogEnable: false
access-log-ignore-urls:
- /report/template
- /system/captcha/get
@@ -0,0 +1,27 @@
--- #################### 注册中心 + 配置中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
username: # Nacos 账号
password: # Nacos 密码
discovery: # 【配置中心】配置项
# namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
config: # 【注册中心】配置项
# namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
# 日志文件配置
logging:
level:
org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示
chenfeng:
gateway:
accessLogEnable: false
access-log-ignore-urls:
- /report/template
- /system/captcha/get
@@ -1,3 +1,14 @@
--- #################### 注册中心 + 配置中心相关配置 ####################
spring:
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
cloud:
nacos:
server-addr: 192.168.1.204:8848 # Nacos 服务器地址
username: nacos # Nacos 账号
password: nacos # Nacos 密码
discovery: # 【配置中心】配置项
namespace: imes-test # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
config: # 【注册中心】配置项
namespace: imes-test # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
+25 -8
View File
@@ -1,10 +1,21 @@
spring:
application:
name: gateway-server
profiles:
active: local
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
codec:
# getway请求大小限制10M1024 * 1024 * 10
max-in-memory-size: 10485760
config:
import:
- optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置
cloud:
# Spring Cloud Gateway 配置项,对应 GatewayProperties 类
gateway:
@@ -79,6 +90,19 @@ spring:
x-forwarded:
prefix-enabled: false # 避免 Swagger 重复带上额外的 /admin-api/system 前缀
server:
port: 48080
# 开启Gzip压缩,默认只压缩超过2048字节的数据
compression:
enabled: true
min-response-size: 2048
mime-types: application/json
# 日志文件配置。注意,如果 logging.file.name 不放在 bootstrap.yaml 配置文件,而是放在 application.yaml 中,会导致出现 LOG_FILE_IS_UNDEFINED 文件
logging:
file:
name: ${user.home}/logs/${spring.application.name} # 日志文件名,全路径
knife4j:
# 聚合 Swagger 文档,参考 https://doc.xiaominfo.com/docs/action/springcloud-gateway 文档
gateway:
@@ -101,11 +125,4 @@ knife4j:
url: /admin-api/plan/v3/api-docs
- name: report-server
service-name: report-server
url: /admin-api/report/v3/api-docs
chenfeng:
gateway:
accessLogEnable: false
access-log-ignore-urls:
- /report/template
- /system/captcha/get
url: /admin-api/report/v3/api-docs
@@ -1,23 +0,0 @@
--- #################### 注册中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: 192.168.1.205:8848
username: nacos
password: nacos
discovery:
#namespace: dev # 命名空间。这里使用 dev 开发环境
--- #################### 配置中心相关配置 ####################
spring:
cloud:
nacos:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config:
server-addr: 192.168.1.205:8848 # Nacos 服务器地址
namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
@@ -1,21 +0,0 @@
--- #################### 注册中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: 127.0.0.1:8848
discovery:
#namespace: dev # 命名空间。这里使用 dev 开发环境
--- #################### 配置中心相关配置 ####################
spring:
cloud:
nacos:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config:
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
namespace: dev # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
@@ -1,23 +0,0 @@
--- #################### 注册中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: 192.168.1.204:8848
username: nacos
password: nacos
discovery:
namespace: imes-test
--- #################### 配置中心相关配置 ####################
spring:
cloud:
nacos:
# Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
config:
server-addr: 192.168.1.204:8848 # Nacos 服务器地址
namespace: imes-test # 命名空间。
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
@@ -1,19 +0,0 @@
spring:
application:
name: gateway-server
profiles:
active: local
server:
port: 48080
# 开启Gzip压缩,默认只压缩超过2048字节的数据
compression:
enabled: true
min-response-size: 2048
mime-types: application/json
# 日志文件配置。注意,如果 logging.file.name 不放在 bootstrap.yaml 配置文件,而是放在 application.yaml 中,会导致出现 LOG_FILE_IS_UNDEFINED 文件
logging:
file:
name: ${user.home}/logs/${spring.application.name} # 日志文件名,全路径