From cca852f148e4a9420cde0be946e38b1f1abde0fa Mon Sep 17 00:00:00 2001 From: zhangli <123879394@qq.com> Date: Wed, 10 Sep 2025 23:35:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=94=B9?= =?UTF-8?q?=E6=88=90nacos=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 1 + pom.xml | 5 ++ .../car/thirdpart/facade/StoreFacade.java | 2 +- src/main/resources/application-local.yml | 3 + src/main/resources/application-test.yml | 0 src/main/resources/application.yml | 84 ------------------- src/main/resources/bootstrap.yml | 15 ++++ 7 files changed, 25 insertions(+), 85 deletions(-) create mode 100644 src/main/resources/application-local.yml create mode 100644 src/main/resources/application-test.yml create mode 100644 src/main/resources/bootstrap.yml diff --git a/Jenkinsfile b/Jenkinsfile index 32653ce..aff7c68 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,6 +59,7 @@ pipeline { --name \${CONTAINER_NAME} \ --network sczx-net \ -p 8083:8083 \ + -e SPRING_PROFILES_ACTIVE=test \ -e JAVA_OPTS="-Xms256m -Xmx512m -Duser.timezone=Asia/Shanghai" \ -e TZ=Asia/Shanghai \ -v /etc/localtime:/etc/localtime:ro \ diff --git a/pom.xml b/pom.xml index e9abfa8..8109cf0 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,11 @@ spring-cloud-starter-alibaba-nacos-discovery + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + org.springframework.cloud spring-cloud-commons diff --git a/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java b/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java index 26b810d..8595378 100644 --- a/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java +++ b/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RequestParam; import java.util.List; -@FeignClient(name = "sczx-store") +@FeignClient(name = "sczx-store", url = "${sczx-store.ribbon.listOfServers:}") public interface StoreFacade { @GetMapping("/pub/getStoreById") diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 0000000..beda27b --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,3 @@ +sczx-store: + ribbon: + listOfServers: http://115.190.8.52:8082 \ No newline at end of file diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 31a06a7..43be47a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,87 +1,3 @@ - -server: - port: 8083 - spring: application: name: sczx-car # 微服务名称 - http: - encoding: - charset: UTF-8 - enabled: true - force: true - mvc: - async: - request-timeout: -1 - cloud: - nacos: - discovery: - server-addr: 115.190.8.52:8848 # Nacos 地址 - group: DEFAULT_GROUP - metadata: - version: 1.0.0 - env: dev - lifecycle: - timeout-per-shutdown-phase: 30s # 设置优雅停机时间 - datasource: - url: jdbc:mysql://115.190.8.52:3306/sczx?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true - username: sczx_user - password: Sczx123@ - driver-class-name: com.mysql.cj.jdbc.Driver - hikari: - maximum-pool-size: 20 # 最大连接数 - minimum-idle: 5 # 最小空闲连接数 - connection-timeout: 30000 # 连接超时时间(毫秒) - idle-timeout: 600000 # 空闲连接超时时间(毫秒) - max-lifetime: 1800000 # 连接最大存活时间(毫秒) - leak-detection-threshold: 60000 # 连接泄漏检测阈值(毫秒) - auto-commit: true - connection_init_sql: SELECT 1 - redis: - host: 115.190.8.52 - port: 6379 - lettuce: - pool: - max-active: 8 - max-wait: 2000ms - max-idle: 4 - min-idle: 1 - max-life-time: 300000ms - -management: - endpoints: - web: - exposure: - include: "*" # 暴露所有监控端点 - endpoint: - health: - show-details: always - -feign: - client: - config: - default: - connectTimeout: 5000 - readTimeout: 5000 - hystrix: - enabled: true # 启用 Feign 的 Hystrix 支持 - -hystrix: - command: - default: - execution: - isolation: - thread: - timeoutInMilliseconds: 10000 # 默认熔断超时时间 - - -mybatis-plus: - mapper-locations: classpath*:mapper/**/*.xml - type-aliases-package: com.sczx.car.po # 实体类包路径 - configuration: - mapUnderscoreToCamelCase: true - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 控制台打印 SQL(调试用) - -auth: - secret-key: his-is-a-very-long-and-secure-secret-key-for-jwt-signing-please-dont-use-short-keys - token-expiration: 86400000 # 24小时 diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..cb2dc9e --- /dev/null +++ b/src/main/resources/bootstrap.yml @@ -0,0 +1,15 @@ +spring: + application: + name: sczx-car # 应用名称,对应 Nacos 配置的 dataId + cloud: + nacos: + server-addr: 115.190.8.52:8848 # Nacos 服务器地址 + config: + group: DEFAULT_GROUP # 配置分组 + file-extension: yaml # 配置文件格式 + timeout: 5000 # 配置读取超时时间 + # 添加共享配置 + shared-configs: + - data-id: shared-config.yaml + group: DEFAULT_GROUP + refresh: true # 是否支持动态刷新 \ No newline at end of file