# ============================================================== # Nacos Configuration Bootstrap # Spring Boot 3.x 使用 bootstrap.yml 而非 bootstrap.properties # ============================================================== spring: application: name: ${SERVICE_NAME:user-service} cloud: # ----------------- 服务发现(注册到Nacos)----------------- nacos: discovery: enabled: true server-addr: ${NACOS_SERVER_ADDR:127.0.0.1:8848} namespace: ${NACOS_NAMESPACE:public} group: ${NACOS_GROUP:DEFAULT_GROUP} instance-count: 1 prefer-ip-address: true # IP和端口(容器环境自动检测,VM环境可手动指定) # ip: ${SERVICE_IP:127.0.0.1} # port: ${SERVER_PORT:8082} # 健康检查配置 heart-beat-interval: 5000 heart-beat-timeout: 15000 # 实例元数据 metadata: version: ${SERVICE_VERSION:1.0.0} environment: ${SPRING_PROFILES_ACTIVE:dev} description: ${SERVICE_DESCRIPTION:用户服务} protocol: http # 负载均衡权重 weight: 1.0 # 开启实例预热(防止流量瞬间涌入新实例) instance-enabled-preheat: true # 订阅(自动发现依赖服务变化) subscribe: true # ----------------- 配置中心(从Nacos读取配置)----------------- config: enabled: true server-addr: ${spring.cloud.nacos.discovery.server-addr} namespace: ${NACOS_NAMESPACE:public} group: ${NACOS_GROUP:DEFAULT_GROUP} file-extension: yaml # 共享配置(公共配置) shared-configs: - data-id: common-config.yaml group: DEFAULT_GROUP refresh: true - data-id: redis-config.yaml group: DEFAULT_GROUP refresh: true - data-id: mysql-config.yaml group: DEFAULT_GROUP refresh: false # 扩展配置(可选) extension-configs: - data-id: ${spring.application.name}-${spring.profiles.active}.yaml group: ${NACOS_GROUP:DEFAULT_GROUP} refresh: true # 刷新机制 refresh-enabled: true # 认证信息 username: ${NACOS_USERNAME:nacos} password: ${NACOS_PASSWORD:nacos123456} # ----------------- 环境变量优先级 ----------------- # 可通过 -DNACOS_SERVER_ADDR=xxx 覆盖 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}