maven指定配置文件部署
打包后文件如下(只包含指定配置文件):
操作步骤:
application.yml文件:
spring: profiles: ##占位符 active: @package.environment@
pom文件:
<!--配置环境的profile--> <profiles> <profile> <id>test</id> <properties> <package.environment>test</package.environment> </properties> </profile> <profile> <!-- 生产环境 --> <id>prod</id> <properties> <package.environment>prod</package.environment> </properties> <activation> <!-- 默认环境 --> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> <!--打包保留文件--> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>application.yml</include> <include>application-${package.environment}.yml</include> <include>**/*.xml</include> </includes> </resource> </resources> </build>
指定打包配置:
clean package -DskipTests -P test
注意:
本地idea运行切换环境的话需要先进行指定打包配置操作,不然target文件没有你切换的配置文件会报错