springboot多环境打包

 

 

 1 配置文件如图

2 application.yml  写一些公共的配置文件

server:
port: 8090
spring:
profiles:
active: @profile.active@


3修改pom。xml

<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.active>dev</profile.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profile.active>test</profile.active>
</properties>
</profile>
<profile>
<id>online</id>
<properties>
<profile.active>online</profile.active>
</properties>
</profile>
</profiles>



<build>
<finalName>dih-server</finalName>

<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/</directory>
<!-- 此配置不可缺,否则mybatis的Mapper.xml将会丢失 -->
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<!--指定资源的位置-->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application*.yml</exclude>
</excludes>
</resource>
<resource>
<filtering>true</filtering> <-- filtering=true 表示可以替换 @profile.active@ 变量 --/>
<directory>src/main/resources</directory>
<!--引入所需环境的配置文件-->
<includes>
<include>application.yml</include>
<include>application-${profile.active}.yml</include>
</includes>
</resource>
</resources>


<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

maven 最后maven打包命令 clean package -U -P dev -pl dih-server -am

























 

posted @ 2020-09-18 17:04  冬天不眠  阅读(401)  评论(0编辑  收藏  举报