I introduced in the previous article: SpringBoot configuration Profile multi-environment support
There is an easier way to achieve the functions we want. Is SpringBootyml multi-document block mode, Just need to be inapplication.ymlIt can be configured in the file.
很简单,直接上配置代码
# 这个代表第一个文档块
server:
port: 8085
spring:
profiles:
active: dev # 当需要哪个环境配置的时候,只需要在这里修改值。
---
# 这个代表第二个文档块
server:
port: 8086
spring:
profiles: dev # 指定dev,代表开发环境
---
# 这个代表第三个文档块
server:
port: 8087
spring:
profiles: pro # 指定pro,代表生产环境
There are three yml document blocks in the code. If there is no configuration, the configuration spring:profiles:active
of the first document block will be used by default. In the case of configuration, the configuration of which yml document block will be used according to the value of the configuration.
Note: The document block is ---
separated by
Test: specify pro environment
Perfect, the configuration takes effect!