多环境下切换不同配置文件
配置文件切换
spring.profiles.active=dev
第一步:首先要有主核心配置文件
application.properties
第二步:添加不同环境下的配置文件
规定:附属配置文件必须以application- 开头
例如开发环境下的配置文件
application-dev.properties
#开发环境配置文件
server.port=8080
server.servlet.context-path=/dev
测试环境下的配置文件
application-test.properties
#测试环境配置文件
server.port=8081
server.servlet.context-path=/test
第三步,在主核心配置文件中声明用哪个配置文件
这样用的就是开发环境的配置文件
spring.profiles.active=dev
如果要切换测试环境下的配置文件
spring.profiles.active=test
value用application-后面的名字即可
多个配置文件同时使用方式
spring.profiles.active=x,xx
使用逗号(,)隔开即可
例子:
application-port.properties
server.port=8080
application-path.properties
server.servlet.context-path=/dev
在主核心配置文件中,要同时使用两个配置文件
spring.profiles.active=port,path
---------------------------------
其他springboot相关知识看专栏其他内容