Profile是Spring对不同环境提供不同配置功能的支持,可通过激活、指定参数等方式快速切换环境。
1、多Profile文件(Properties格式)
application.properties: 默认全局配置文件
application-dev.properties: 开发环境
application-prod.properties: 生产环境
application-test.properties: 测试环境
2、yml支持多文档块方式
server:
port: 8080
spring:
profiles:
active: dev
---
server:
port: 8084
spring:
profiles: dev
---
server:
port: 8085
spring:
profiles: prod
---
server:
port: 8086
spring:
profiles: test
3、激活指定Profile
spring.profiles.active=...
来指定当前的环境,并使用对应的application-{profile}.properties或者application.yml所对应profile下的配置作为当前环境使用的配置信息。虚拟机参数:
Edit Configurations
--->VM options
---->-Dspring.profiles.active=...
命令行:
打包用命令
java -jar xxxx.jar --spring.profiles.active=...
IDEA运行设置:
Edit Configurations
--->Program arguments
---->
====================打个广告,欢迎关注====================
QQ: | 412425870 |
微信公众号:Cay课堂 | ![]() |
csdn博客: | http://blog.youkuaiyun.com/caychen |
码云: | https://gitee.com/caychen/ |
github: | https://github.com/caychen |
点击群号或者扫描二维码即可加入QQ群: | ![]() |
| ![]() |