SpringCloud配置中心使用多环境profile配置

说明

由于springcloud配置中心和springboot的多环境配置并没有打通,

所以使用java -jar xxxx.jar --spring.profiles.active=prod命令只能对springboot项目中的配置有效,

并不能从配置中心获取不同的环境配置,想要实现目标还需要多做一些工作。

项目配置

在bootstrap.yml文件中配置配置中心,如下所示

使用三个短横线将不同环境分隔开,这样可以在一个文件中完成多个环境配置

spring:
  profiles:
    active: dev
---
spring:
  profiles: dev
  cloud:
    bootstrap:
      enabled: false
    config:
      uri: http://localhost:8888
      name: webclient
      profile: dev
---
spring:
  profiles: test
  cloud:
    bootstrap:
      enabled: false
    config:
      uri: http://localhost:8888
      name: webclient
      profile: test
---
spring:
  profiles: prod
  cloud:
    bootstrap:
      enabled: false
    config:
      uri: http://localhost:8888
      name: webclient
      profile: prod

启动项目

使用以下命令指定环境配置并启动项目

java -jar xxxx.jar --spring.profiles.active=prod

 

 

你可能感兴趣的:(SpringCloud配置中心使用多环境profile配置)