# 20200917 配置中心如何支持多环境配置
SpringCloudAlibaba使用nacos作为配置中心,需要使用bootstrap.yml,但是不支持bootstrap-{profile}.yml,如何解决这种问题呢?两种解决方案(为了方便阅读,我把yml格式转成properties):
1. 第一种:通过---分隔不同环境(参考图1):
spring.profiles.active: dev
---
# 开发环境
spring.profiles: dev
具体配置
---
# 测试环境
spring.profiles: test
---
# 演示环境
spring.profiles: demo
2. 第二种使用pom.xml打包不同环境的配置,然后bootstrap.yml通过变量引用(参考图2和图3)
<profiles>
<profile>
<id>dev</id>
<properties></properties>
</profile>
<profile>
<id>test</id>
<properties></properties>
</profile>
<profile>
<id>demo</id>
<properties></properties>
</profile>
</profiles>
bootstrap.xml引用:
key:${key}