In this paper, the source code making address: laughed told https://github.com/cicadasmile/spring-boot-baseCopy the code

One, packaging introduction

Springboot can be packaged in a number of ways. Can play war package, can play JAR package, can use Jekins package deployment. War packages are not recommended. SpringBoot can be separated from the front and back ends to facilitate deployment by using JARS.

Customize the startup page

=======================
        No BUG
=======================
Copy the code

This replaces the original SpringBoot boot style.

Three, package configuration

1. Package poM configuration

<! -- Project Build -->
<build>
    <finalName>${project.artifactId}</finalName>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <! -- SpringBoot plugin: JDK compiler plugin -->
        <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: package -->
        <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 tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
    </plugins>
</build>
Copy the code

2. Multi-environment configuration

1) Application.yml configuration

server:
  port: 8017
spring:
  application:
    name: node17-boot-package
  profiles:
    active: dev
Copy the code

2) application-dev.yml configuration

project:
  sign: develop
Copy the code

3) Application-pro.yML configuration

project:
  sign: product
Copy the code

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 (a){
        returnsign ; }}Copy the code

Four, package execution

1. Specify module packaging

mvn clean install -pl node17-boot-package -am -Dmaven.test.skip=trueGenerate Jar package: node17-boot-package. JarCopy the code

2. Run the Jar package

Run java-jar node17-boot-package.jar –spring.profiles. Active =dev Run pro java-jar node17-boot-package.jar –spring.profiles.active=pro

http://localhost:8017/getSign dev environment print: develop pro environmental printing: the productCopy the code

Five, source code address

Making address: given a smile cloud address: https://github.com/cicadasmile/spring-boot-base code laughed told https://gitee.com/cicadasmile/spring-boot-baseCopy the code