A Brief Introduction to Packaging
Springboot is packaged in many ways. You can use war packages, jar packages, and jekins for packaging and deployment. It is not recommended to use war packages. SpringBoot is suitable for front-end and back-end separation. It is more convenient and fast to deploy as jar.
Custom Start Page
Content of banner.txt
======================= No BUG =======================
This replaces the original SpringBook startup style.
Packing Configuration
1. Packing pom configuration
<!-- Project construction --> <build> <finalName>${project.artifactId}</finalName> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <!-- SpringBoot Plug-in unit: JDK Compiler plug-in --> <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 Plug-in: Packing --> <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> <!-- Skip unit testing --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
2. Multi-environment Configuration
1) application.yml configuration
server: port: 8017 spring: application: name: node17-boot-package profiles: active: dev
2) application-dev.yml configuration
project: sign: develop
3) application-pro.yml configuration
project: sign: product
3. Environment Test Interface
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 ; } }
IV. Packaging Execution
1. Designated Module Packaging
mvn clean install -pl node17-boot-package -am -Dmaven.test.skip=true //Generate Jar packages: node17-boot-package.jar
2. Running the Jar package
Running dev environment
java -jar node17-boot-package.jar --spring.profiles.active=dev
Running pro environment
java -jar node17-boot-package.jar --spring.profiles.active=pro
http://localhost:8017/getSign dev Environment Printing: develop pro Environment Printing: product
5. Source code address
GitHub Address: Know a smile https://github.com/cicadasmile/spring-boot-base Code Yun Address: Know a smile https://gitee.com/cicadasmile/spring-boot-base