config(gateway): 配置中心和日志配置外置到Nacos
- 添加Nacos配置中心依赖并启用配置导入功能 - 将网关日志配置外置到Nacos gateway-server.yaml文件 - 将业务模块日志文件路径配置外置到Nacos rdms-common.yaml - 在pom.xml中设置addResources为false避免占位符不被替换 - 添加logback-spring.xml配置文件用于日志格式化和滚动策略 - 优化日志配置管理方式,实现按环境统一配置
This commit is contained in:
@@ -54,6 +54,12 @@
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Config 配置中心相关 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
@@ -77,6 +83,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<configuration>
|
||||
<!-- 必须为 false:addResources=true 会让 spring-boot:run 直接挂载源 resources 目录、
|
||||
跳过资源过滤,导致 application.yaml 里的 @nacos.xxx@ 占位符不被替换。 -->
|
||||
<addResources>false</addResources>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
||||
@@ -17,8 +17,13 @@ spring:
|
||||
main:
|
||||
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
|
||||
|
||||
# 配置中心:网关独享一份 dataId,不共用业务侧 rdms-common.yaml(其数据库/Redis/MyBatis 等配置网关用不到)。
|
||||
config:
|
||||
import:
|
||||
- nacos:gateway-server.yaml # 网关专属配置(日志路径等),需先在 Nacos 建好该 dataId
|
||||
|
||||
cloud:
|
||||
# 注册中心连接(值由根 pom 的 nacos.* 属性在打包时注入)。网关仅用 Nacos 做服务发现,不加载配置中心文件。
|
||||
# 注册中心 + 配置中心连接(值由根 pom 的 nacos.* 属性在打包时注入)。
|
||||
nacos:
|
||||
server-addr: @nacos.server-addr@
|
||||
username: @nacos.username@
|
||||
@@ -26,6 +31,9 @@ spring:
|
||||
discovery:
|
||||
namespace: @nacos.namespace@
|
||||
group: @nacos.group@
|
||||
config:
|
||||
namespace: @nacos.namespace@
|
||||
group: @nacos.group@
|
||||
# Spring Cloud Gateway 配置项,对应 GatewayProperties 类
|
||||
gateway:
|
||||
server:
|
||||
@@ -86,11 +94,7 @@ spring:
|
||||
server:
|
||||
port: 48080
|
||||
|
||||
logging:
|
||||
file:
|
||||
name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径
|
||||
level:
|
||||
org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR
|
||||
# 日志配置(logging.file.name + level)已整体外置到 Nacos gateway-server.yaml,按环境统一管理,本地不再定义以免覆盖。
|
||||
|
||||
# Actuator 监控端点的配置项
|
||||
management:
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<appender-ref ref="FILE"/>
|
||||
</appender>
|
||||
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<!-- 本地环境下,如果不想【FILE】打印日志,可以注释掉本行 -->
|
||||
|
||||
Reference in New Issue
Block a user