From 1225d8387eb18f068cc96935c72fad389533858b Mon Sep 17 00:00:00 2001 From: zhangjf Date: Sun, 22 Feb 2026 16:10:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E7=A6=BB=E4=B8=BA=E7=BB=9F=E4=B8=80=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=92=8C=E4=B8=AA=E6=80=A7=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增service.properties:每个服务独立的个性化配置 - APP_NAME: 服务名称 - INSTANCE_NAME: 实例名称(多租户场景) - TENANT_ID: 租户标识 - env.properties:所有服务共用的统一配置 - Nacos/Redis/日志等公共参数 - 加载顺序:先env.properties,后service.properties(个性化覆盖统一) - 更新assembly.xml:service.properties打包到conf目录 - 更新启动脚本:统一使用load_properties函数加载配置 --- assembly/assembly.xml | 1 + .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 13 +++++ .../src/main/resources/service.properties | 18 +++++++ scripts/env.properties | 12 +---- scripts/start.sh | 48 +++++++++++-------- scripts/status.sh | 34 +++++++------ scripts/stop.sh | 33 +++++++------ 14 files changed, 190 insertions(+), 60 deletions(-) create mode 100644 fund-cust/src/main/resources/service.properties create mode 100644 fund-exp/src/main/resources/service.properties create mode 100644 fund-file/src/main/resources/service.properties create mode 100644 fund-gateway/src/main/resources/service.properties create mode 100644 fund-proj/src/main/resources/service.properties create mode 100644 fund-receipt/src/main/resources/service.properties create mode 100644 fund-report/src/main/resources/service.properties create mode 100644 fund-req/src/main/resources/service.properties create mode 100644 fund-sys/src/main/resources/service.properties diff --git a/assembly/assembly.xml b/assembly/assembly.xml index 6813753..d187ce0 100644 --- a/assembly/assembly.xml +++ b/assembly/assembly.xml @@ -37,6 +37,7 @@ application.yml logback-spring.xml bootstrap.yml + service.properties diff --git a/fund-cust/src/main/resources/service.properties b/fund-cust/src/main/resources/service.properties new file mode 100644 index 0000000..2497648 --- /dev/null +++ b/fund-cust/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-cust + +# 实例名称(多租户场景使用) +INSTANCE_NAME=${APP_NAME} + +# 租户标识 +TENANT_ID= diff --git a/fund-exp/src/main/resources/service.properties b/fund-exp/src/main/resources/service.properties new file mode 100644 index 0000000..5601965 --- /dev/null +++ b/fund-exp/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-exp + +# 实例名称(多租户场景使用) +INSTANCE_NAME=${APP_NAME} + +# 租户标识 +TENANT_ID= diff --git a/fund-file/src/main/resources/service.properties b/fund-file/src/main/resources/service.properties new file mode 100644 index 0000000..320b36a --- /dev/null +++ b/fund-file/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-file + +# 实例名称 +INSTANCE_NAME=${APP_NAME} + +# 租户标识(文件服务为共享服务,无需租户标识) +TENANT_ID= diff --git a/fund-gateway/src/main/resources/service.properties b/fund-gateway/src/main/resources/service.properties new file mode 100644 index 0000000..1e5c1dd --- /dev/null +++ b/fund-gateway/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-gateway + +# 实例名称(多租户场景使用) +INSTANCE_NAME=${APP_NAME} + +# 租户标识 +TENANT_ID= diff --git a/fund-proj/src/main/resources/service.properties b/fund-proj/src/main/resources/service.properties new file mode 100644 index 0000000..71651c5 --- /dev/null +++ b/fund-proj/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-proj + +# 实例名称(多租户场景使用) +INSTANCE_NAME=${APP_NAME} + +# 租户标识 +TENANT_ID= diff --git a/fund-receipt/src/main/resources/service.properties b/fund-receipt/src/main/resources/service.properties new file mode 100644 index 0000000..358f7a0 --- /dev/null +++ b/fund-receipt/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-receipt + +# 实例名称(多租户场景使用) +INSTANCE_NAME=${APP_NAME} + +# 租户标识 +TENANT_ID= diff --git a/fund-report/src/main/resources/service.properties b/fund-report/src/main/resources/service.properties new file mode 100644 index 0000000..534b5e6 --- /dev/null +++ b/fund-report/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-report + +# 实例名称 +INSTANCE_NAME=${APP_NAME} + +# 租户标识(报表服务为共享服务,无需租户标识) +TENANT_ID= diff --git a/fund-req/src/main/resources/service.properties b/fund-req/src/main/resources/service.properties new file mode 100644 index 0000000..8bae419 --- /dev/null +++ b/fund-req/src/main/resources/service.properties @@ -0,0 +1,13 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称 +APP_NAME=fund-req + +# 实例名称(多租户场景使用) +INSTANCE_NAME=${APP_NAME} + +# 租户标识 +TENANT_ID= diff --git a/fund-sys/src/main/resources/service.properties b/fund-sys/src/main/resources/service.properties new file mode 100644 index 0000000..d2dcbfb --- /dev/null +++ b/fund-sys/src/main/resources/service.properties @@ -0,0 +1,18 @@ +# ============================================ +# 服务个性化配置 +# 此文件随服务打包,每个服务独立配置 +# ============================================ + +# 服务名称(对应JAR文件名,用于Nacos服务注册) +APP_NAME=fund-sys + +# 实例名称(多租户场景使用,默认与APP_NAME相同) +# 多租户示例:fund-sys-shared, fund-sys-vip001 +INSTANCE_NAME=${APP_NAME} + +# 租户标识(多租户场景使用,用于Nacos元数据路由) +# 空值=共享实例,有值=VIP专属实例 +TENANT_ID= + +# 服务端口(可覆盖application.yml中的配置) +# SERVER_PORT=8100 diff --git a/scripts/env.properties b/scripts/env.properties index dbd190e..eb7fa2e 100644 --- a/scripts/env.properties +++ b/scripts/env.properties @@ -1,17 +1,9 @@ # ============================================ -# 环境变量配置文件 +# 环境变量配置文件(所有服务共用) # 服务启动时会加载此文件 +# 注意:个性化参数请在各服务的service.properties中配置 # ============================================ -# -------------------------------------------- -# 实例配置(多租户模式需要修改) -# -------------------------------------------- -# 实例名称(用于区分多租户实例,如fund-sys-shared, fund-sys-vip001) -# 默认与JAR文件名相同,多租户模式下需要修改 -# INSTANCE_NAME=fund-sys -# 租户标识(多租户模式使用,用于Nacos元数据路由) -TENANT_ID= - # -------------------------------------------- # Nacos配置(所有服务共用) # -------------------------------------------- diff --git a/scripts/start.sh b/scripts/start.sh index 959d293..1805cdf 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -6,34 +6,42 @@ SCRIPT_DIR=$(dirname "$(readlink -f "$0")") APP_HOME=$(dirname "$SCRIPT_DIR") -# 自动从lib目录下的JAR文件推断APP_NAME +# 加载函数:读取properties文件 +load_properties() { + local file="$1" + if [ -f "$file" ]; then + while IFS='=' read -r key value; do + [[ "$key" =~ ^#.*$ ]] && continue + [[ -z "$key" ]] && continue + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$file" + fi +} + +# 1. 加载统一环境配置 +load_properties "${APP_HOME}/conf/env.properties" + +# 2. 加载服务个性化配置(覆盖统一配置) +load_properties "${APP_HOME}/conf/service.properties" + +# 3. 设置默认值 +APP_NAME=${APP_NAME:-"unknown"} +INSTANCE_NAME=${INSTANCE_NAME:-${APP_NAME}} +TENANT_ID=${TENANT_ID:-""} + +# 4. JAR文件路径 JAR_FILE=$(ls ${APP_HOME}/lib/*.jar 2>/dev/null | head -1) if [ -z "$JAR_FILE" ]; then echo "Error: No JAR file found in ${APP_HOME}/lib/" exit 1 fi -APP_NAME=$(basename "$JAR_FILE" .jar) -# 加载环境变量配置 -if [ -f "${APP_HOME}/conf/env.properties" ]; then - while IFS='=' read -r key value; do - [[ "$key" =~ ^#.*$ ]] && continue - [[ -z "$key" ]] && continue - key=$(echo "$key" | xargs) - value=$(echo "$value" | xargs) - # 跳过APP_NAME,因为已从JAR文件推断 - [[ "$key" == "APP_NAME" ]] && continue - export "$key=$value" - done < "${APP_HOME}/conf/env.properties" -fi - -# 实例名称(用于区分多租户实例,默认与APP_NAME相同) -INSTANCE_NAME=${INSTANCE_NAME:-${APP_NAME}} - -# 日志目录(使用INSTANCE_NAME区分不同实例) +# 5. 日志目录(使用INSTANCE_NAME区分不同实例) LOG_HOME="/datacfs/applogs/${INSTANCE_NAME}" -# PID文件路径(使用INSTANCE_NAME) +# 6. PID文件路径 PID_FILE="${APP_HOME}/${INSTANCE_NAME}.pid" # JVM参数(可通过环境变量覆盖) diff --git a/scripts/status.sh b/scripts/status.sh index d99e2bf..3382063 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -6,24 +6,28 @@ SCRIPT_DIR=$(dirname "$(readlink -f "$0")") APP_HOME=$(dirname "$SCRIPT_DIR") -# 自动从lib目录下的JAR文件推断APP_NAME -JAR_FILE=$(ls ${APP_HOME}/lib/*.jar 2>/dev/null | head -1) -APP_NAME=$(basename "$JAR_FILE" .jar) +# 加载函数:读取properties文件 +load_properties() { + local file="$1" + if [ -f "$file" ]; then + while IFS='=' read -r key value; do + [[ "$key" =~ ^#.*$ ]] && continue + [[ -z "$key" ]] && continue + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$file" + fi +} -# 加载环境变量配置 -if [ -f "${APP_HOME}/conf/env.properties" ]; then - while IFS='=' read -r key value; do - [[ "$key" =~ ^#.*$ ]] && continue - [[ -z "$key" ]] && continue - key=$(echo "$key" | xargs) - value=$(echo "$value" | xargs) - [[ "$key" == "APP_NAME" ]] && continue - export "$key=$value" - done < "${APP_HOME}/conf/env.properties" -fi +# 加载配置文件(先统一,后个性化) +load_properties "${APP_HOME}/conf/env.properties" +load_properties "${APP_HOME}/conf/service.properties" -# 实例名称 +# 设置默认值 +APP_NAME=${APP_NAME:-"unknown"} INSTANCE_NAME=${INSTANCE_NAME:-${APP_NAME}} +TENANT_ID=${TENANT_ID:-""} # PID文件路径 PID_FILE="${APP_HOME}/${INSTANCE_NAME}.pid" diff --git a/scripts/stop.sh b/scripts/stop.sh index 71e4bd8..8d0393a 100755 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -6,23 +6,26 @@ SCRIPT_DIR=$(dirname "$(readlink -f "$0")") APP_HOME=$(dirname "$SCRIPT_DIR") -# 自动从lib目录下的JAR文件推断APP_NAME -JAR_FILE=$(ls ${APP_HOME}/lib/*.jar 2>/dev/null | head -1) -APP_NAME=$(basename "$JAR_FILE" .jar) +# 加载函数:读取properties文件 +load_properties() { + local file="$1" + if [ -f "$file" ]; then + while IFS='=' read -r key value; do + [[ "$key" =~ ^#.*$ ]] && continue + [[ -z "$key" ]] && continue + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$file" + fi +} -# 加载环境变量配置 -if [ -f "${APP_HOME}/conf/env.properties" ]; then - while IFS='=' read -r key value; do - [[ "$key" =~ ^#.*$ ]] && continue - [[ -z "$key" ]] && continue - key=$(echo "$key" | xargs) - value=$(echo "$value" | xargs) - [[ "$key" == "APP_NAME" ]] && continue - export "$key=$value" - done < "${APP_HOME}/conf/env.properties" -fi +# 加载配置文件(先统一,后个性化) +load_properties "${APP_HOME}/conf/env.properties" +load_properties "${APP_HOME}/conf/service.properties" -# 实例名称 +# 设置默认值 +APP_NAME=${APP_NAME:-"unknown"} INSTANCE_NAME=${INSTANCE_NAME:-${APP_NAME}} # PID文件路径