217 lines
6.6 KiB
YAML
217 lines
6.6 KiB
YAML
# ==============================================================
|
||
# user-service Nacos配置示例
|
||
# 完整配置,复制到 src/main/resources/application.yml
|
||
# ==============================================================
|
||
|
||
server:
|
||
port: ${SERVER_PORT:8082}
|
||
servlet:
|
||
context-path: /user
|
||
tomcat:
|
||
threads:
|
||
max: 200
|
||
min-spare: 10
|
||
max-connections: 10000
|
||
accept-count: 100
|
||
|
||
spring:
|
||
application:
|
||
name: user-service
|
||
|
||
# 数据源配置
|
||
datasource:
|
||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3307}/erp_java?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||
username: ${MYSQL_USER:erp_user}
|
||
password: ${MYSQL_PASSWORD:erp123456}
|
||
hikari:
|
||
connection-timeout: 30000
|
||
maximum-pool-size: 20
|
||
minimum-idle: 5
|
||
idle-timeout: 600000
|
||
max-lifetime: 1800000
|
||
connection-test-query: SELECT 1
|
||
pool-name: UserServiceHikariPool
|
||
|
||
# Redis配置
|
||
redis:
|
||
host: ${REDIS_HOST:localhost}
|
||
port: ${REDIS_PORT:6379}
|
||
password: ${REDIS_PASSWORD:redis123456}
|
||
database: 0
|
||
timeout: 3000ms
|
||
lettuce:
|
||
pool:
|
||
max-active: 20
|
||
max-idle: 10
|
||
min-idle: 5
|
||
|
||
# MyBatis配置
|
||
mybatis-plus:
|
||
configuration:
|
||
map-underscore-to-camel-case: true
|
||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||
global-config:
|
||
db-config:
|
||
logic-delete-field: deletedAt
|
||
logic-delete-value: NOW()
|
||
logic-not-delete-value: NULL
|
||
|
||
# ==============================================================
|
||
# Spring Cloud Alibaba Nacos 配置(核心部分)
|
||
# ==============================================================
|
||
cloud:
|
||
nacos:
|
||
# ---------- 服务发现与注册 ----------
|
||
discovery:
|
||
# Nacos服务器地址(集群模式用VIP)
|
||
server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848}
|
||
# 命名空间(环境隔离)
|
||
namespace: ${NACOS_NAMESPACE:public}
|
||
# 分组(业务隔离)
|
||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||
# 实例ID格式:${ip}#${port}#${cluster}#${serviceName}#${namespace}
|
||
instance-id: ${spring.cloud.nacos.discovery.ip}#${server.port}#DEFAULT#${spring.application.name}#${spring.cloud.nacos.discovery.namespace}
|
||
# 是否优先使用IP注册
|
||
prefer-ip-address: true
|
||
# IP地址(容器环境自动检测,VM环境可手动指定)
|
||
# ip: ${SERVICE_IP:127.0.0.1}
|
||
# 端口(通常不用指定,会自动检测)
|
||
# port: ${SERVER_PORT:8082}
|
||
# 集群名称
|
||
cluster-name: DEFAULT
|
||
# 权重(负载均衡用)
|
||
weight: 1.0
|
||
# 实例数量(单机=1)
|
||
instance-count: 1
|
||
# 是否开启实例预热(防止流量瞬间涌入)
|
||
instance-enabled-preheat: true
|
||
|
||
# ---------- 心跳配置 ----------
|
||
# 心跳间隔(默认5秒)
|
||
heart-beat-interval: 5000
|
||
# 心跳超时时间(默认15秒)
|
||
heart-beat-timeout: 15000
|
||
# 实例删除超时(默认30秒)
|
||
ip-delete-timeout: 30
|
||
# 是否开启优雅下线
|
||
enabled-healthy-rule: true
|
||
|
||
# ---------- 实例元数据 ----------
|
||
metadata:
|
||
version: ${SERVICE_VERSION:1.0.0}
|
||
environment: ${SPRING_PROFILES_ACTIVE:dev}
|
||
description: 用户服务 - 用户管理、认证、权限
|
||
owner: erp-team
|
||
protocol: http
|
||
tags: auth,user,permission
|
||
|
||
# ---------- 订阅 ----------
|
||
# 是否订阅服务变化(服务发现)
|
||
subscribe: true
|
||
|
||
# ---------- 配置中心 ----------
|
||
config:
|
||
enabled: true
|
||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||
namespace: ${NACOS_NAMESPACE:public}
|
||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||
file-extension: yaml
|
||
# 刷新机制
|
||
refresh-enabled: true
|
||
# 共享配置
|
||
shared-configs:
|
||
- data-id: common-config.yaml
|
||
group: DEFAULT_GROUP
|
||
refresh: true
|
||
- data-id: redis-config.yaml
|
||
group: DEFAULT_GROUP
|
||
refresh: true
|
||
# 扩展配置
|
||
extension-configs:
|
||
- data-id: ${spring.application.name}-${spring.profiles.active}.yaml
|
||
group: ${NACOS_GROUP:DEFAULT_GROUP}
|
||
refresh: true
|
||
|
||
# ---------- 认证信息 ----------
|
||
username: ${NACOS_USERNAME:nacos}
|
||
password: ${NACOS_PASSWORD:nacos123456}
|
||
|
||
# profiles环境
|
||
profiles:
|
||
active: ${SPRING_PROFILES_ACTIVE:dev}
|
||
|
||
# ==============================================================
|
||
# Actuator健康检查配置
|
||
# ==============================================================
|
||
management:
|
||
endpoints:
|
||
web:
|
||
exposure:
|
||
include: health,info,metrics,env,prometheus
|
||
base-path: /actuator
|
||
endpoint:
|
||
health:
|
||
show-details: always
|
||
probes:
|
||
enabled: true
|
||
path: /actuator/health
|
||
info:
|
||
enabled: true
|
||
health:
|
||
nacos:
|
||
enabled: true
|
||
redis:
|
||
enabled: true
|
||
db:
|
||
enabled: true
|
||
metrics:
|
||
export:
|
||
prometheus:
|
||
enabled: true
|
||
tags:
|
||
application: ${spring.application.name}
|
||
|
||
# ==============================================================
|
||
# 日志配置
|
||
# ==============================================================
|
||
logging:
|
||
level:
|
||
com.erp.user: ${LOG_LEVEL_USER:DEBUG}
|
||
org.springframework.cloud.alibaba.nacos: ${LOG_LEVEL_NACOS:INFO}
|
||
com.alibaba.nacos: ${LOG_LEVEL_NACOS_CLIENT:INFO}
|
||
pattern:
|
||
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId}] %-5level %logger{36} - %msg%n"
|
||
|
||
# ==============================================================
|
||
# JWT配置
|
||
# ==============================================================
|
||
jwt:
|
||
secret: ${JWT_SECRET:erp-java-backend-secret-key-for-jwt-signing-must-be-at-least-256-bits-long-2026}
|
||
access-token-expiration: 900
|
||
refresh-token-expiration: 604800
|
||
remember-me-expiration: 2592000
|
||
|
||
# ==============================================================
|
||
# 安全配置
|
||
# ==============================================================
|
||
security:
|
||
max-login-attempts: 5
|
||
lock-duration-minutes: 30
|
||
attempt-expire-minutes: 60
|
||
max-reset-attempts: 3
|
||
reset-attempt-expire-minutes: 60
|
||
reset-token-expiry-minutes: 30
|
||
password-history-size: 5
|
||
|
||
# ==============================================================
|
||
# 服务配置
|
||
# ==============================================================
|
||
service:
|
||
auth:
|
||
enabled: true
|
||
rate-limit:
|
||
enabled: true
|
||
capacity: 100
|
||
refill-rate: 10
|