IDEA configure hot start

1.Background

        During the development process, when we finish writing a function, we need to run the application test. There may be multiple small bugs in this small function. We need to correct it and restart the server. This invisibly slows down the development speed and increases the development time. SpringBoot Spring-boot-devtools is provided to automatically restart the application when we change the application and configuration files!

2. Hot start configuration steps

        1) Add Spring Boot DevTools dependency :

        2) Display configuration in yml

        2) Configure IDE : In your integrated development environment (IDE), ensure that the automatic build and hot swap (Hot Swap) functions are enabled.

        4 ) Start the application: Run the main class of your Spring Boot application to start the application.

        5) Modify code testing: Make changes and add functional tests in the code.

View changes: After you make code changes, save the file and view the console or browser, you will see that the application automatically reloads the modified code and any changes will take effect at runtime.

2.1.Introduction to spring-boot-devtools

  • spring-boot-devtools is a development tool for developing Spring Boot applications. It provides many useful functions to help developers improve development efficiency and debugging capabilities.
  • Using spring-boot-devtools, you can automatically monitor changes in the application's class files and static resources, and automatically restart the application when there are changes, thus saving the time of recompiling and manual restarting.
  • spring-boot-devtools also provides an embedded developer tools page, which can be used to view application details, such as automatic configuration reports, loaded beans, etc.
  • By defining the corresponding properties in the application.properties file, spring-boot-devtools can be configured, such as turning off automatic restart, specifying the delay time triggered by resource changes, etc.

2.2. Add dependencies to the project

        In the project's pom.xml file, add the Spring Boot DevTools dependency. This can be achieved by adding the following line inside the tag in pom.xml <dependencies>:

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

2.3.yml configuration

spring:
  devtools:
    restart:
      enabled: true  #设置开启热部署
      additional-paths: src/main/java #重启目录
      exclude: WEB-INF/**

2.4. Set up IDEA automatic compilation

        1) Use the shortcut key Ctrl+Alt+S to open the settings, go to (Build, Execotion, Deployment) -> Compiler-> check the Build Project automatically item and restart IDEA.
![Insert image description here](https://img-blog.csdnimg.cn/a69623fe3fd94ac7bc9054511be37dff.png

        2) Press the shortcut keys Ctrl + Shift + Alt + / at the same time, the following box will pop up, select Registry

        3) Check compiler.automake.allow.when.app running and compiler.document.save.enabled (specify whether to enable saving project response when the document is changed), and appropriately reduce their corresponding save action delay times, or Using the default value is also fine. Of course, when I didn't modify its default value, I found that when the project was modified, it took a long time for it to automatically warm-start (you can reduce the corresponding time or refer to the solution in the next section of this article).

        4) Restart the application . When changing the code, observe the console output. You will find that Spring Boot has detected the file changes and restarted.

4. The difference between hot start and hot deployment

        Hot start refers to the ability to restart an already running project (modification of code and configuration files) without loading some things, thereby starting faster, saving development time, and avoiding a complete restart when starting the application.
        Hot deployment means that changes to code, configuration, or resources can be made while the application is running without stopping or restarting the application. Hot deployment allows developers to quickly deploy updates without affecting the normal operation of the application.

        Hot start mainly focuses on the overall restart process of the application, while hot deployment focuses more on dynamically updating and replacing some components or functions. Both are intended to reduce system downtime and increase system availability.

Guess you like

Origin blog.csdn.net/qq_20957669/article/details/132549532