An overview of the

In the Web project development of Spring Boot, we often encounter the modification of source code files and configuration files. However, after each modification, the Web server must be restarted to make the modified files take effect, which is time-consuming and affects the development efficiency. In hot deployment, you do not need to restart the Web server to ensure that the modification of files takes effect immediately.

Spring – the boot – devtools is introduced

  • Spring-boot-devtools is a developer service module that can implement Spring Boot hot deployment. The most important feature is to automatically change the application code to the latest App.

  • Spring-boot-devtools enables hot deployment of pages, class files (the modification of class files does not take effect immediately), and property configuration files. The idea is that spring-boot-DevTools listens for file changes in the Classpath and restarts the application immediately (at save time).

  • Due to the virtual machine mechanism, only the Class under development is loaded during the restart, and no third-party JAR package is reloaded, so the restart is very fast.

Configuring hot Deployment

  • In the POM.xml file, add the projectspring-boot-devtoolsRely on
<! -- Hot deployment dependencies -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
 </dependency>

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <! Hot deployment will not work without this configuration.
    <configuration>
        <fork>true</fork>
    </configuration>
 </plugin>
Copy the code
  • In the resource fileapplication.propertiesTo configure hot deployment
The cache will be disabled immediately after the page is modified. Immediately flush spring. Thymeleaf. Cache = false # hot deployment into force the spring. The devtools. Restart. Enabled = true # set need to restart the directory Spring. Devtools. Restart. Additional - paths = SRC/Java / # main Settings don't need to restart the directory Spring. Devtools. Restart. Exclude = static / * *, public / * *, WEB - INF / * * # for mybatis, Production environment can remove # restart. Include. Mapper = / mapper - / - \ \. \ \ w + jar # restart. Include the pagehelper = / pagehelper - / - \ \. \ \ w + jarCopy the code

When the hot deployment setup is complete, the program only needs to start once. When the code is modified later, the hot deployment mechanism can be triggered only after saving, and the service can be restarted automatically.

Set the IDEA environment to compile automatically

When using the IDEA compiler, you need to set up automatic compilation.

  • Check it in the compiler optionsBuild project automaticallyoptions

  • Use shortcut keys:Ctrl + Alt + Shift + /Bring up the Registry window and check itcompiler.automake.allow.when.app.runningoptions

The source address

springboot-devtools