spring boot项目多环境配置及多环境打包

^_^的我 1年前 ⋅ 1031 阅读

顶层项目增加配置

<!-- 增加在pom文件下的project级下 -->
<profiles>
	<profile>
		<id>dev</id>
       <properties>
           <profileActive>dev</profileActive>
       </properties>
       <activation>
           <!--指定默认激活-->
           <activeByDefault>true</activeByDefault>
       </activation>
   </profile>
   <profile>
       <id>pro</id>
       <properties>
           <profileActive>pro</profileActive>
       </properties>
   </profile>
   <profile>
       <id>test</id>
       <properties>
           <profileActive>test</profileActive>
       </properties>
   </profile>
   <profile>
       <id>release</id>
       <properties>
           <profileActive>release</profileActive>
       </properties>
   </profile>
</profiles>

provider项目增加配置

<!-- 增加在pom文件下的project级下 -->
<build>
    <finalName>innovation-vouchers-service</finalName>
    <plugins>
     <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <executions>
             <execution>
                 <goals>
                     <goal>repackage</goal>
                 </goals>
             </execution>
         </executions>
    </plugin>
  </plugins>
  <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>bootstrap-pro.yml</exclude>
                <exclude>bootstrap-dev.yml</exclude>
                <exclude>bootstrap-test.yml</exclude>
                <exclude>bootstrap-release.yml</exclude>
            </excludes>
        </resource>
        <!--需要动态添加的资源-->
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <!--读取打包命令中指定的环境-->
                <include>bootstrap-${profileActive}.yml</include>
                <include>bootstrap.yml</include>
            </includes>
        </resource>
    </resources>
</build>

配置文件

微信截图_20190905170028.png

打包命令

# -P表示加载的环境,test为加载test配置
mvn clean compile package -Dmaven.test.skip=true -Ptest

全部评论: 0

    我有话说: