[Java development framework SpringBoot] yml multi-document block mode

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:activeof 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
Insert picture description here
Perfect, the configuration takes effect!

to sum up

如果觉得不错,可以点赞+收藏或者关注下博主。感谢阅读!

Guess you like

Origin blog.csdn.net/weixin_42825651/article/details/109220904