SpringBoot 项目的 Maven 多环境打包配置

Stella981
• 阅读 564

1. 在pom.xml文件中配置

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <activatedProperties>dev</activatedProperties>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <activatedProperties>test</activatedProperties>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <activatedProperties>prod</activatedProperties>
        </properties>
    </profile>
</profiles>

配置finalName打包后文件名中包含环境信息

<build>
    <finalName>springboot-demo-${activatedProperties}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

2. 在application.properties中配置当前激活的环境

spring.profiles.active=@activatedProperties@

3. 使用 mvn 命令进行打包

mvn clean package -P dev
mvn clean package -P test
mvn clean package -P prod

在 eclipse 中配置

SpringBoot 项目的 Maven 多环境打包配置

4. 使用 java -jar 命令选择不同环境启动

java -jar project-demo.jar --spring.profiles.active=prod

# 后台启动方式
nohup java -jar project-demo.jar --spring.profiles.active=prod > /dev/null 2>&1 &
点赞
收藏
评论区
推荐文章
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
2年前
java实现使用QQ邮箱发送验证码功能
首先当然是导入jar包了啊如果是maven项目可以进maven资源库进行搜索导入,在此附上地址:https://mvnrepository.com这是需要导入的jar包 commonsemail1.x.jar、mail.jar  activation.jar,其中activation.jar我并没有导入,但是还是发送成功了,但看网上有蛮多都说需
Easter79 Easter79
2年前
springboot分环境打包(maven动态选择环境)
分环境打包核心点:spring.profiles.activepom.xml中添加:<profiles<profile<iddev</id<activation<activeByDefaulttrue</activeB
Stella981 Stella981
2年前
Spring Boot 2.3 新特配置文件属性跟踪
背景当我们使用springboot在多环境打包,配置属性在不同环境的值不同,如下:spring:profiles:active:@project.profile@根据maven动态配置profilespring:profiles:devd
Stella981 Stella981
2年前
Spring 学习笔记(三):Spring Bean
1Bean配置Spring可以看做是一个管理Bean的工厂,开发者需要将Bean配置在XML或者Properties配置文件中。实际开发中常使用XML的格式,其中<bean中的属性或子元素如下:id:Bean在BeanFactory中的唯一标识,在代码中通过BeanFac
Stella981 Stella981
2年前
MyBatis基于Maven的入门
主要内容如下: 1.myBatis在maven中的配置 2.myBatis在工程中的config配置文件3.myBatis为Bean和表的映射文件4.myBatis基本的使用 myBatis在maven中的配置,在pom.xml中增加内容       1.增加依赖 ,mybatis的,还有mysql的驱动的
Stella981 Stella981
2年前
SpringBoot集成mybatis以及自动化测试代码实现
Mybatis和logback的应用配置1、在module的pom.xml文件中,加载springboot和swagger、lombok、fastjson、mysql、mybatis包2、在resources中添加配置:配置文件有两种,一种是properties,另一种是yaml,这里使用yamlyaml配
Stella981 Stella981
2年前
Maven学习
MavenProfile通过使用profile可以根据不同的环境和目标做出不同的编译打包行为,如下pom文件<profiles<profile<iddev</idxxxx</profile
Stella981 Stella981
2年前
Maven使用 国内镜像配置
Maven使用国内镜像配置  Maven  setting.xml中配置<repositories<repository<idnexus</id<namelocalprivatenexus</name
Easter79 Easter79
2年前
SpringBoot集成mybatis以及自动化测试代码实现
Mybatis和logback的应用配置1、在module的pom.xml文件中,加载springboot和swagger、lombok、fastjson、mysql、mybatis包2、在resources中添加配置:配置文件有两种,一种是properties,另一种是yaml,这里使用yamlyaml配