1、多Profile文件

我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml;而且默认使用application.properties的配置;例如我们创建application-dev.properties,在其中命名端口号为8083

Profile多环境支持

运行后,发现端口号是application.properties的:

Profile多环境支持

这说明,多个配置文件存在时,则存在一定的优先级。

如果我们**dev环境:

Profile多环境支持

则会发现端口号变为dev下的8083:

Profile多环境支持

 

同时,yml还支持多文档块方式

Profile多环境支持

 

3、**指定profile(profile的多环境支持)

​       3.1 在配置文件中指定  spring.profiles.active=dev

在idea上方点击:

Profile多环境支持

之后在program arguments中输入spring.profiles.active=dev

Profile多环境支持

​       3.2 在命令行中指定:

我们可以打包成一个jar包:

Profile多环境支持

生成好之后,右键target

Profile多环境支持

 

输入cmd:

Profile多环境支持

输入java -jar demo-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev,回车

注意,如果电脑没有安装jdk,则会报如下错误:

Profile多环境支持

 

​       3.3 虚拟机参数;

​              -Dspring.profiles.active=dev

Profile多环境支持

 

相关文章: