共计 2191 个字符,预计需要花费 6 分钟才能阅读完成。
本文源码
GitHub 地址:知了一笑
https://github.com/cicadasmile/spring-boot-base
一、打包简介
springboot 的打包方式有很多种。可以打 war 包,可以打 jar 包,可以使用 jekins 进行打包部署的。不推荐用 war 包,SpringBoot 适合前后端分离,打成 jar 进行部署更加方便快捷。
二、自定义启动页
banner.txt 内容
=======================
No BUG
=======================
这样就替换了原先 SpringBoot 的启动样式。
三、打包配置
1、打包 pom 配置
<!-- 项目构建 -->
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- SpringBoot 插件:JDK 编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- SpringBoot 插件:打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 跳过单元测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
2、多环境配置
1)application.yml 配置
server:
port: 8017
spring:
application:
name: node17-boot-package
profiles:
active: dev
2)application-dev.yml 配置
project:
sign: develop
3)application-pro.yml 配置
project:
sign: product
3、环境测试接口
package com.boot.pack.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PackController {@Value("${project.sign}")
private String sign ;
@RequestMapping("/getSign")
public String getSign (){return sign ;}
}
四、打包执行
1、指定模块打包
mvn clean install -pl node17-boot-package -am -Dmaven.test.skip=true
生成 Jar 包:node17-boot-package.jar
2、运行 Jar 包
运行 dev 环境
java -jar node17-boot-package.jar –spring.profiles.active=dev
运行 pro 环境
java -jar node17-boot-package.jar –spring.profiles.active=pro
http://localhost:8017/getSign
dev 环境打印:develop
pro 环境打印:product
五、源代码地址
GitHub 地址:知了一笑
https://github.com/cicadasmile/spring-boot-base
码云地址:知了一笑
https://gitee.com/cicadasmile/spring-boot-base
正文完
发表至:无分类
2019-07-18