JDK: 1.8
SpringBoot: 1.5.10.RELEASE
Profile 是 Spring 针对不同环境提供不同配置功能的支持,可以通过激活指定参数等方式快速切换环境配置。
多 profile 文件形式
properties
applicaiton.properties
1 | server.port=8081 |
application-dev.properties
1 | server.port=8082 |
application-prod.properties
1 | server.port=8083 |
yml
application.yml
1 | server: |
application-dev.yml
1 | server: |
application-prod.yml
1 | server: |
YAML 多 profile 文档块形式
YAML 可以通过 ---
表示多个文档块,并且通过 spring.profiles 指定各个文档块的 profiles 环境
1 | server: |
激活 profile 方式
在默认配置文件中指定
application.properties:
1 | spring.profiles.active=dev |
application.ym:
1 | spring: |
命令行指定
1 | --spring.profiles.active=dev |
1 | java -jar XXX.jar --spring.profiles.active=dev |
JVM 参数指定
1 | -Dspring.profiles.active=dev |