diff --git a/JY-Core/src/main/resources/application.yaml b/JY-Core/src/main/resources/application.yaml index d4da8ab8..2de77e63 100644 --- a/JY-Core/src/main/resources/application.yaml +++ b/JY-Core/src/main/resources/application.yaml @@ -1,138 +1,2 @@ -spring: - datasource: - url: jdbc:mysql://localhost:3306/jayu_cloud?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai - servlet: - multipart: - max-file-size: 5MB - max-request-size: 10MB - jackson: - time-zone: Asia/Shanghai - date-format: yyyy-MM-dd HH:mm:ss - -logging: - pattern: - console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" - -server: - servlet: - encoding: - charset: UTF-8 - force: true - enabled: true - timezone: Asia/Shanghai - -mybatis: - configuration: - map-underscore-to-camel-case: true - -jayu-cloud: - brand: - message-template-name: ${PLATFORM_MESSAGE_TEMPLATE_NAME:JayuCloud} - manager-register-shop-description: ${PLATFORM_MANAGER_REGISTER_SHOP_DESCRIPTION:Jayu Salon注册店铺} - security: - jwt: - issuer: jayu-cloud - access-token-expiration-seconds: 7200 - remember-me-access-token-expiration-seconds: 604800 - refresh-token-expiration-seconds: 604800 - clock-skew-seconds: 30 - signature: - enabled: true - window-seconds: 300 - nonce-retention-seconds: 600 - rate-limit: - login: - limit: 10 - window-seconds: 60 - send-code: - limit: 5 - window-seconds: 60 - reset-password: - limit: 5 - window-seconds: 600 - authenticated-write: - limit: 80 - window-seconds: 60 - order-create: - limit: 10 - window-seconds: 60 - cache: - local-max-size: 2048 - product-detail: - local-ttl-seconds: 120 - redis-ttl-seconds: 900 - product-list: - local-ttl-seconds: 60 - redis-ttl-seconds: 300 - product-search: - local-ttl-seconds: 60 - redis-ttl-seconds: 300 - shop: - local-ttl-seconds: 180 - redis-ttl-seconds: 900 - tag: - local-ttl-seconds: 300 - redis-ttl-seconds: 1200 - object-storage-file: - local-ttl-seconds: 300 - redis-ttl-seconds: 1800 - dashboard: - local-ttl-seconds: 30 - redis-ttl-seconds: 90 - slow-request: - enabled: true - threshold-ms: 300 - log-response-header-request-id: true - http-client: - connect-timeout-ms: 3000 - read-timeout-ms: 5000 - connection-request-timeout-ms: 1000 - max-total-connections: 200 - max-connections-per-route: 50 - -object-storage: - provider-order: - - MINIO - - QINIU_KODO - - ALIYUN_OSS - replica-required-providers: - - MINIO - - QINIU_KODO - - ALIYUN_OSS - primary-provider: MINIO - backup-provider: QINIU_KODO,ALIYUN_OSS - signed-url-expire-minutes: 60 - backup-queue-name: jayu-cloud.file.object-storage.backup.queue - backup-exchange-name: jayu-cloud.file.object-storage.backup.exchange - backup-routing-key: jayu-cloud.file.object-storage.backup - backup-retry-batch-limit: 500 - backup-retry-cron: "0 0 2 * * ?" - -qiniu: - kodo: - access-key: ${QINIU_KODO_ACCESS_KEY:} - secret-key: ${QINIU_KODO_SECRET_KEY:} - bucket-name: ${QINIU_KODO_BUCKET_NAME:} - domain: ${QINIU_KODO_DOMAIN:} - zone: ${QINIU_KODO_ZONE:z2} - private-bucket: ${QINIU_KODO_PRIVATE_BUCKET:true} - signed-url-expire-minutes: ${QINIU_KODO_SIGNED_URL_EXPIRE_MINUTES:60} - -minio: - enabled: ${MINIO_ENABLED:false} - endpoint: ${MINIO_ENDPOINT:} - bucket-name: ${MINIO_BUCKET_NAME:} - access-key: ${MINIO_ACCESS_KEY:} - secret-key: ${MINIO_SECRET_KEY:} - private-bucket: ${MINIO_PRIVATE_BUCKET:true} - signed-url-expire-minutes: ${MINIO_SIGNED_URL_EXPIRE_MINUTES:60} - -aliyun: - oss: - enabled: ${ALIYUN_OSS_ENABLED:false} - endpoint: ${ALIYUN_OSS_ENDPOINT:} - region: ${ALIYUN_OSS_REGION:} - bucket-name: ${ALIYUN_OSS_BUCKET_NAME:} - access-key-id: ${ALIYUN_OSS_ACCESS_KEY_ID:} - access-key-secret: ${ALIYUN_OSS_ACCESS_KEY_SECRET:} - signed-url-expire-minutes: ${ALIYUN_OSS_SIGNED_URL_EXPIRE_MINUTES:60} +# 本文件不承载业务配置。 +# Core 运行配置统一从 Nacos 加载,Nacos 连接信息由 bootstrap.yaml 和环境变量提供。 diff --git a/JY-Core/src/main/resources/bootstrap.yaml b/JY-Core/src/main/resources/bootstrap.yaml index 9611f8ab..a52539b8 100644 --- a/JY-Core/src/main/resources/bootstrap.yaml +++ b/JY-Core/src/main/resources/bootstrap.yaml @@ -8,9 +8,9 @@ spring: # Nacos 集群地址,默认指向开发环境,生产环境通过环境变量覆盖。 server-addr: ${NACOS_SERVER_ADDR:192.168.5.103:8848} # Nacos 命名空间,默认指向开发环境。 - namespace: jayu-cloud-dev + namespace: ${NACOS_NAMESPACE:JayuCloud-Dev} # 服务注册分组。 - group: DEFAULT_GROUP + group: ${NACOS_GROUP:DEFAULT_GROUP} # 注册到 Nacos 的服务名。 service: ${spring.application.name} # 是否启用服务发现。 @@ -18,14 +18,14 @@ spring: # 是否将当前服务注册到 Nacos。 register-enabled: true # Nacos 认证用户名。 - username: xiaowang + username: ${NACOS_USERNAME:} # Nacos 认证密码。 - password: 122503wcy.... + password: ${NACOS_PASSWORD:} config: # Nacos 配置中心地址,与服务发现使用同一组集群节点,默认指向开发环境。 server-addr: ${NACOS_SERVER_ADDR:192.168.5.103:8848} # Nacos 配置中心命名空间,默认指向开发环境。 - namespace: jayu-cloud-dev + namespace: ${NACOS_NAMESPACE:JayuCloud-Dev} # 配置分组。 group: ${NACOS_GROUP:DEFAULT_GROUP} # Core 服务独有配置文件。 @@ -35,9 +35,9 @@ spring: # 是否启用配置中心。 enabled: true # Nacos 认证用户名。 - username: ${NACOS_USERNAME:xiaowang} + username: ${NACOS_USERNAME:} # Nacos 认证密码。 - password: ${NACOS_PASSWORD:122503wcy....} + password: ${NACOS_PASSWORD:} # Core 与 Gateway 共享的公共配置文件。 shared-configs: - data-id: infra.yaml diff --git a/JY-Gateway/src/main/resources/application.yaml b/JY-Gateway/src/main/resources/application.yaml index 1f85a5a9..8dfd585b 100644 --- a/JY-Gateway/src/main/resources/application.yaml +++ b/JY-Gateway/src/main/resources/application.yaml @@ -1,163 +1,2 @@ -spring: - cloud: - gateway: - routes: - # 前台API路由 - - id: product-route - uri: lb://jy-core - predicates: - - Path=/api/product/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: product-like-route - uri: lb://jy-core - predicates: - - Path=/api/product-like/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: shop-route - uri: lb://jy-core - predicates: - - Path=/api/shop/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: user-route - uri: lb://jy-core - predicates: - - Path=/api/user/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: comment-route - uri: lb://jy-core - predicates: - - Path=/api/comment/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: balance-route - uri: lb://jy-core - predicates: - - Path=/api/balance/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: tag-route - uri: lb://jy-core - predicates: - - Path=/api/tag/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: file-route - uri: lb://jy-core - predicates: - - Path=/api/file/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: permission-route - uri: lb://jy-core - predicates: - - Path=/api/permission/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: coupon-route - uri: lb://jy-core - predicates: - - Path=/api/coupon/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: cart-route - uri: lb://jy-core - predicates: - - Path=/api/cart/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: order-route - uri: lb://jy-core - predicates: - - Path=/api/order/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: wishlist-route - uri: lb://jy-core - predicates: - - Path=/api/wishlist/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: nail-artist-route - uri: lb://jy-core - predicates: - - Path=/api/nail-artist/** - filters: - - RewritePath=/api/(?.*), /${remaining} - - id: legal-agreement-route - uri: lb://jy-core - predicates: - - Path=/api/legal-agreement/** - filters: - - RewritePath=/api/(?.*), /${remaining} - # 后台管理API路由(/api/admin/** 格式) - - id: admin-api-route - order: -10 - uri: lb://jy-core - predicates: - - Path=/api/admin/** - filters: - - RewritePath=/api/admin/(?.*), /admin/${remaining} - # 后台管理API路由(/admin/api/** 格式) - - id: admin-route - order: -9 - uri: lb://jy-core - predicates: - - Path=/admin/api/** - filters: - - RewritePath=/admin/api/(?.*), /admin/${remaining} - - id: admin-auth-compat-route - order: -8 - uri: lb://jy-core - predicates: - - Path=/admin/auth/** - # 前台API兜底路由,避免 Core 新增模块后 Gateway 未同步导致 404 - - id: frontend-fallback-route - order: 100 - uri: lb://jy-core - predicates: - - Path=/api/** - filters: - - RewritePath=/api/(?.*), /${remaining} - -jayu-cloud: - security: - jwt: - issuer: jayu-cloud - clock-skew-seconds: 30 - gateway: - whitelist: - - /api/user/login - - /api/user/register - - /api/user/check/** - - /api/user/refresh-token - - /api/user/send-verification-code - - /api/user/phone-login - - /api/user/wechat-mini/** - - /api/user/reset-password-by-phone - - /api/nail-artist/profile/** - - /api/nail-artist/*/availability - - /api/nail-artist/*/reviews - - /api/shop/list - - /api/shop/list/simple - - /api/legal-agreement/current - - /api/legal-agreement/current/** - - /api/health/** - - /api/error - - /api/admin/auth/login - - /api/admin/auth/login-shops/** - - /api/admin/auth/refresh - - /api/admin/auth/register - - /admin/auth/login - - /admin/auth/login-shops/** - - /admin/auth/refresh - - /admin/api/auth/login - - /admin/api/auth/login-shops/** - - /admin/api/auth/refresh - slow-request: - enabled: true - threshold-ms: 300 - log-response-header-request-id: true +# 本文件不承载业务配置。 +# Gateway 路由、鉴权白名单和运行参数统一从 Nacos 加载。 diff --git a/JY-Gateway/src/main/resources/bootstrap.yaml b/JY-Gateway/src/main/resources/bootstrap.yaml index f38044ee..a7cb27e4 100644 --- a/JY-Gateway/src/main/resources/bootstrap.yaml +++ b/JY-Gateway/src/main/resources/bootstrap.yaml @@ -8,20 +8,20 @@ spring: # Nacos 集群地址,默认指向开发环境,生产环境通过环境变量覆盖。 server-addr: ${NACOS_SERVER_ADDR:192.168.5.103:8848} # Nacos 命名空间,默认指向开发环境 - namespace: jayu-cloud-dev + namespace: ${NACOS_NAMESPACE:JayuCloud-Dev} # 服务注册分组。 group: ${NACOS_GROUP:DEFAULT_GROUP} # 注册到 Nacos 的服务名。 service: ${spring.application.name} # Nacos 认证用户名。 - username: ${NACOS_USERNAME:xiaowang} + username: ${NACOS_USERNAME:} # Nacos 认证密码。 - password: ${NACOS_PASSWORD:122503wcy....} + password: ${NACOS_PASSWORD:} config: # Nacos 配置中心地址,与服务发现使用同一组集群节点,默认指向开发环境。 server-addr: ${NACOS_SERVER_ADDR:192.168.5.103:8848} # Nacos 配置中心命名空间,默认指向开发环境。 - namespace: jayu-cloud-dev + namespace: ${NACOS_NAMESPACE:JayuCloud-Dev} # 配置分组。 group: ${NACOS_GROUP:DEFAULT_GROUP} # Gateway 服务独有配置文件。 @@ -29,9 +29,9 @@ spring: # 所有 Nacos 配置均使用 YAML。 file-extension: yaml # Nacos 认证用户名。 - username: ${NACOS_USERNAME:xiaowang} + username: ${NACOS_USERNAME:} # Nacos 认证密码。 - password: ${NACOS_PASSWORD:122503wcy....} + password: ${NACOS_PASSWORD:} # Core 与 Gateway 共享的公共配置文件。 shared-configs: - data-id: infra.yaml diff --git a/scripts/应用配置迁移到Nacos说明_20260630.md b/scripts/应用配置迁移到Nacos说明_20260630.md new file mode 100644 index 00000000..5ff12e02 --- /dev/null +++ b/scripts/应用配置迁移到Nacos说明_20260630.md @@ -0,0 +1,66 @@ +# 应用配置迁移到 Nacos 说明 + +## 背景 + +Core 启动时报错: + +```text +Failed to bind properties under 'qiniu.kodo' +``` + +报错来源显示为本地 `application.yaml`,说明应用最终绑定到了本地空字符串配置,而不是开发环境 Nacos 中的真实配置。 + +## 原因 + +- `JY-Core/src/main/resources/application.yaml` 中保留了数据库、缓存、对象存储、七牛、MinIO、阿里云 OSS、JWT、缓存策略等运行配置。 +- 七牛 Kodo 的本地配置使用空字符串作为默认值,和 `QiniuKodoConfig` 的 `@NotBlank` 校验冲突。 +- `bootstrap.yaml` 中 Nacos namespace 和部分认证信息写死,环境切换时容易连接到错误命名空间或泄露本地默认账号密码。 + +## 处理方式 + +- `JY-Core/src/main/resources/application.yaml` 改为占位说明文件,不再承载业务配置。 +- `JY-Gateway/src/main/resources/application.yaml` 改为占位说明文件,不再承载路由和鉴权配置。 +- Core 与 Gateway 的 `bootstrap.yaml` 保留最小 Nacos 启动配置。 +- Nacos 地址、命名空间、分组、账号和密码统一由环境变量控制。 +- 开发环境默认命名空间为 `JayuCloud-Dev`。 + +## 本机开发环境变量 + +本机用户环境变量需要包含: + +```powershell +NACOS_SERVER_ADDR=192.168.5.103:8848 +NACOS_NAMESPACE=JayuCloud-Dev +NACOS_GROUP=DEFAULT_GROUP +NACOS_USERNAME=xiaowang +NACOS_PASSWORD=通过受控渠道保存 +``` + +修改后需要重启 IDE、终端或运行服务的进程,确保新环境变量被进程读取。 + +## Nacos 配置要求 + +开发环境 `JayuCloud-Dev / DEFAULT_GROUP` 必须存在: + +- `core.yaml` +- `gateway.yaml` +- `infra.yaml` +- `secret.yaml` +- `logging.yaml` + +七牛 Kodo 必填配置应放在 `infra.yaml` 和 `secret.yaml`: + +- `qiniu.kodo.bucket-name` +- `qiniu.kodo.domain` +- `qiniu.kodo.access-key` +- `qiniu.kodo.secret-key` +- `qiniu.kodo.zone` +- `qiniu.kodo.private-bucket` +- `qiniu.kodo.signed-url-expire-minutes` + +## 验证方式 + +1. 启动 Core,确认日志中加载开发环境 Nacos 配置。 +2. 确认不再出现 `qiniu.kodo` 绑定空字符串的启动错误。 +3. 访问 Core 健康检查接口。 +4. 上传文件做对象存储冒烟验证。