SpringBoot有时候会在开发环境下,有时候是在测试环境下,怎么创建多个环境并且选择制定环境呢?
properties文件下
可以在resources文件夹下创建多个application-xxx.properties
或者是yaml文件
一般来说,默认使用application.properties
如果要切换环境在application.properties
文件中加入spring.profiles.active=xxxx
如spring.profiles.active=test
,xxxx指的是application-后面的名称,比如上面的test或development
yaml文件下
server:
port: 8081
profiles:
active: dev
---
#yaml文件用三个-隔开一组配置
#profiles代表名称
server:
profiles: develop
port: 8082
---
#yaml文件用三个-隔开一组配置
#profiles代表名称
server:
profiles: test
port: 8083