srpingBoot配置多环境配置文件
1.默认配置文件 application.yml
2.添加配置文件 application-prod.yml,application-test.yml,application-dev.yml,
3.在application.yml中增加spring的配置文件选择,注意这里是在spring.profiles.active下,用@profiles.active@来代替变动的文件名如prod,dev,test,这里我用单引号括起来是因为启动时候出现异常
Exception in thread "main" while scanning for the next token found character '@' that cannot start any token. (Do not use @ for indentation) in 'reader', line 4, column 11: name: @project.artifactId@
所以这里用单引号括起来
4.修改pom,在pom中增加配置文件
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 资源根目录排除各环境的配置,防止在生成目录中多余其它目录 -->
<filtering>true</filtering>
<excludes>
<exclude>application*.yml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>application-${profiles.active}.yml</include>
</includes>
</resource>
</resources>
</build>
<!-- 不同环境的配置 -->
<profiles>
<!--开发环境-->
<profile>
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<!--默认激活-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--测试环境-->
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
<!--生产环境-->
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
</properties>
</profile>
</profiles>
5.在idea的maven框中选择不同的profiles下的选项,即可启动不同环境,打包的时候也会只打入所选择的profiles下对应的yml文件
linux下的docker操作命令及异常