“This is the 10th day of my participation in the August Gwen Challenge.

Take a look at the Spring Boot 2.x properties configuration file for details

Modify based on the above code

Devtools developer tools

During the development phase, we often had to modify the code, which required constant rebooting of the Spring Boot application, which was cumbersome.

Spring Boot provides a developer tool to monitor files on the classpath path. Spring Boot applications can be restarted automatically whenever the source code or configuration file is modified. This feature is useful during the development phase.

To use this developer feature, simply add the following dependencies to the pom.xml file:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>
Copy the code

Start the application directly, then modify the source code and save it. You can see the auto-compiled results from the console log output, and Spring Boot will automatically reload.

By default, changes to files in the /static, /public, and /templates directories do not restart automatically

Because when caching is disabled, changes to these static files are updated in real time.

Package to pack

The Maven build tool is used here, and you can also use the Gradle plug-in

Spring Boot provides spring-boot-Maven-plugin for packaging all dependencies on a single JAR file (spring Boot built-in Tomcat server, So a packaged JAR file can run directly on any platform based on the JVM.)

Pom configuration

Add the following configuration to the pom.xml file:

<project .>.<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                
                <! -- Exclude compilation of Lombok plugin -->
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
	</build>
</project>
Copy the code

Maven build

Without any configuration, Spring Boot’s plugin automatically locates the main entry file of the application, which can be packaged with the following Maven command:

#cdTo the root directory of the project
mvnw clean package  -Dmaven.test.skip=true
#or
mvn clean package  -Dmaven.test.skip=true
Copy the code

-dmaven.test. skip=true indicates that the test file is skipped.

As you can see in the following figure, the packaged file is generated in the target directory named spring-boot-0.0.1- snapshot. jar by default.

Running jar files

–server.port Specifies the port number

Java jar spring - the boot - 0.0.1 - the SNAPSHOT. The jar - server port = 8932Copy the code

The runtime can also specify the profile runtime profile, such as using the application-dev.yml profile

Java jar spring - the boot - 0.0.1 - the SNAPSHOT. Jar -- spring. Profiles. The active = devCopy the code

You can also set JVM parameters:

Java -xms10m -xmx80m -jar spring-boot 0.0.1 -snapshot.jar &Copy the code

If you don’t want the admin window to disappear, you can run it in the background (Linux) :

Nohup Java -jar spring-boot-0.0.1 -snapshot.jar &Copy the code

View the Java runtime environment

You can use the jinfo command that comes with Java:

#Pid indicates the process ID
jinfo -flags pid
Copy the code
  • Linux can use the ps command
  • The CONSOLE log of IDEA also displays the PID process id of the service in debug mode
  • In Windows, you can view the PID of the process in Task Manager -> Details

Such as:

VM Flags:
-XX:CICompilerCount=4 -XX:ConcGCThreads=2 -XX:G1ConcRefinementThreads=8 -XX:G1HeapRegionSize=1048576 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=266338304 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=805306368 -XX:MaxNewSize=4823
44960 -XX:MinHeapDeltaBytes=1048576 -XX:NonNMethodCodeHeapSize=5836300 -XX:NonProfiledCodeHeapSize=122910970 -XX:ProfiledCodeHeapSize=122910970 -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPoint
ers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation
Copy the code
  • -XX:CICompilerCount

    The maximum number of parallel compilations

  • – XX: InitialHeapSize and – XX: MaxHeapSize

    Specifies the JVM’s initial and maximum heap memory sizes

  • -XX:MaxNewSize

    The maximum allocatable size of new generation memory in the JVM heap region

  • -XX:+UseG1GC

    Garbage collection uses the G1 collector