springboot 如何进行多环境配置
1. 配置pom.xml
<!-- 配置三个环境 dev fat prd -->
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 自定义属性env,在不同环境有不同的值 -->
<env>dev</env>
</properties>
<activation>
<!-- 默认激活dev环境的配置 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>fat</id>
<properties>
<env>fat</env>
</properties>
</profile>
<profile>
<id>prd</id>
<properties>
<env>prd</env>
</properties>
</profile>
</profiles>
<build>
<!-- 指定filter,根据最终profile下的env属性获取对应的配置文件 -->
<filters>
<filter>config/${env}</filter>
</filters>
<!-- 开启资源过滤,让Maven能解析资源文件中的Maven属性 -->
<resources>
<!--新的配置文件路径-->
<resource>
<directory>config/${env}</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
2. 新建配置文件,如图

获取系统信息:
String osName = System.getProperties().getProperty("os.name");

浙公网安备 33010602011771号