springboot学习五:多环境的切换
一、多环境的切换(profile)
a. properties
默认boot会读取application.properties环境8882
多个:
application-环境名.properties
application-dev.properties 8883
application-test.properties 8884
1.如果要选择某一个具体的环境: application.properties中指定:
spring.profiles.active=环境名
2.配置文件优先级:application.properties>application-dev.properties>application.yml
3.如果将application.properties注释掉,spring boot仍然会读取其他appilcation-环境名.properties中的配置。
4.并且properties的优先级高于yml
#
二、最终端口为8888
server:
port: 8080
spring:
profiles:
active: dev
---
server:
port: 8888
spring:
profiles: dev
---
server:
port: 8882
spring:
profiles: test
#
三、动态切换环境
i:通过运行参数指定环境
(1)STS(Eclipse) :Run Configuration - Argument - program Argument
--spring.profiles.active=环境名
(2)打成jar包命令行方式:
java -jar 项目名.jar --spring.profiles.active=环境名
ii:通过vm参数指定环境
STS(Eclipse) :Run Configuration - Argument - VM
-Dspring.profiles.active=环境名
(3)idea设置springboot端口
#
官网对多配置时的顺序说明:https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/\#boot-features-external-config
还没有评论,来说两句吧...