本文源码 GitHub地址:知了一笑 https://github.com/cicadasmile/spring-boot-base
springboot的打包方式有很多种。可以打war包,可以打jar包,可以使用jekins进行打包部署的。不推荐用war包,SpringBoot适合前后端分离,打成jar进行部署更加方便快捷。
banner.txt内容
======================= No BUG =======================
这样就替换了原先SpringBoot的启动样式。
<!-- 项目构建 --> <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>
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
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 ; } }
mvn clean install -pl node17-boot-package -am -Dmaven.test.skip=true 生成Jar包:node17-boot-package.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