[IntelliJ IDEA] Automatic restart Spring Boot application in IntelliJ IDEA Application update policies with spring-boot-devtools

Automatic restart Spring Boot application

With the spring-boot-devtools module, your application will restart every time files on the classpath change. If IntelliJ IDEA is configured to continuously compile changed files, you can set a trigger file. In this case your application will restart only after you modify the trigger file. For more information, see Automatic Restart Developing with Spring Boot - https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.restart.

Enable automatic restart

Spring Boot includes an additional set of tools that can make the application development experience a little more pleasant. The spring-boot-devtools module can be included in any project to provide additional development-time features. To include devtools support, add the module dependency to your build, as shown in the following listings for Maven and Gradle:

Add the spring-boot-devtools module dependency for your project.

Maven

Open the pom.xml file and add the following dependency under dependencies:

1
2
3
4
5
6
7
<!-- pom.xml -->

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

Setting the spring-boot-devtools dependency as optional prevents it from being used in other modules that use your project.

Gradle

Open the build.gradle file and add the following dependency under dependencies:

1
2
3
// build.gradle

developmentOnly("org.springframework.boot:spring-boot-devtools")

Setting the spring-boot-devtools dependency as developmentOnly prevents it from being used in other modules that use your project.

To update a running application in IntelliJ IDEA, select Run | Debugging Actions | Update Application ⌘F10 from the main menu, or select your application in the Services tool window and click Update application. Depending on your needs, you can configure what the IDE will do when you execute this action.

If the Spring Boot run configurations are not available in the Services tool window, either add them or use the Run or Debug tool window.

Configure the application update options

If you have an application server run configuration, you can specify what it should do when you initiate an update.

  • From the main menu, select Run | Edit Configurations.

  • Open the application server run configuration.

Configure the following options:

  • On ‘Update’ action: Select what to do when you initiate an update.

  • On frame deactivation: Select what to do when you switch from IntelliJ IDEA to a different application (for example, to a web browser).

Update a running application

When you launch the application server run configuration and it successfully deploys and runs the application, you can modify the code and update your application in one of the following ways:

  • Press ⌘F10.

  • From the main menu, select Run | Debugging Actions | Update application.

  • Click the Update Application button in the Run or Debug tool window.

If the necessary update option is associated with frame deactivation, the application will update automatically when you switch from IntelliJ IDEA to a different application (for example, a web browser).

FAQs

How do you set a value in the IntelliJ Registry?

If you are using OS X, you can open the registry by typing cmd + shift + A. Type registry and change the value of the option you’re looking for.

java - How do you set a value in the IntelliJ Registry? - Stack Overflow - https://stackoverflow.com/questions/28415695/how-do-you-set-a-value-in-the-intellij-registry

References

[1] Update applications on application servers | IntelliJ IDEA - https://www.jetbrains.com/help/idea/updating-applications-on-application-servers.html

[2] Spring Boot | IntelliJ IDEA - https://www.jetbrains.com/help/idea/spring-boot.html#application-update-policies

[3] Alter the program’s execution flow | IntelliJ IDEA - https://www.jetbrains.com/help/idea/altering-the-program-s-execution-flow.html#reload_classes

[4] Developing with Spring Boot - https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools

[5] Intellij IDEA – Spring boot reload static file is not working - Mkyong.com - https://mkyong.com/spring-boot/intellij-idea-spring-boot-template-reload-is-not-working/