一. 多环境配置的好处:
1.不同环境配置可以配置不同的参数~
2.便于部署,提高效率,减少出错~
二. properties多环境配置
resources目录下配置文件
application.properties
application-dev.properties
application-prd.properties
application-test.properties
application.properties设置环境配置
#激活哪一个环境的配置文件
spring.profiles.active=dev
#公共配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss:运行的时候还可以制定激活的环境
java -jar myapp.jar --spring.profiles.active=prd
#激活哪一个环境的配置文件
#公共配置
spring:
profiles:
active: prd ##配置prd
jackson:
date-format: yyyy-MM-dd HH:mm:ss
---
spring:
profiles: dev
server:
port: 8081
---
spring:
profiles: test
server:
port: 8082
---
spring:
profiles: prd
server:
port: 8083
四.两种配置方式的比较
1. Properties配置多环境,需要添加多个配置文件,YAML只需要一个配件文件
本文探讨了Spring Boot中实现多环境配置的重要性,包括在不同环境中配置不同参数以提高部署效率和降低错误率。文章介绍了在resources目录下创建如application-dev、application-prd和application-test等特定环境的配置文件,并在application.properties中设置环境配置的方法。同时对比了Properties与YAML配置多环境的差异,指出Properties需要多个文件而YAML仅需一个。

被折叠的 条评论
为什么被折叠?



