首页 技术 正文
技术 2022年11月14日
0 收藏 742 点赞 3,696 浏览 1176 个字

分环境打包核心点:spring.profiles.active

pom.xml中添加:

<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<logback.loglevel>DEBUG</logback.loglevel>
<spring.profiles.active>dev</spring.profiles.active>
<profileActive>dev</profileActive>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<logback.loglevel>INFO</logback.loglevel>
<spring.profiles.active>test</spring.profiles.active>
<profileActive>test</profileActive>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<logback.loglevel>INFO</logback.loglevel>
<spring.profiles.active>prod</spring.profiles.active>
<profileActive>prod</profileActive>
</properties>
</profile>
</profiles>

  

resources目录下的配置文件:

springboot分环境打包(maven动态选择环境)

其中,向application.yml文件中添加:

spring:
profiles:
active: @profileActive@

完成后,看看pom.xml文件中是有build模块(一般创建springboot项目会在pom.xml文件下自动生成),如果没有添加:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

然后再Terminal控制台输入maven打包命令:

  1. 选择dev环境(默认):
mvn clean package
  1. 选择test环境:
mvn clean package -P test
  1. 选择prod环境:
mvn clean package -P prod

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289