'IntelliJ IDEA spring boot hot reload on manual save?

My goal is:

  1. Disable autosave in IntelliJ IDEA for a spring boot project

  2. Hot reload the project always when files are manually saved

Seems to me that it is impossible to achieve these two goals simultaneously.

I can disable autosave in IntelliJ IDEA by modifying these settings:

Build, Execution, Deployment -> Compiler Uncheck Build project automatically

Also I think what is too needed is modify these options:

Appearance & Behaviour -> System Settings Uncheck both save files under Synchronization (frame deactivation and save files automatically)

I can enable hot reload by the help of Mkyong: Mkyong-help As you can see from the link, it requires setting 'Build project automatically' on. If I do both of these steps, then the application will always save on edit, and it will always hot reload the app.

This is so frustrating, I thought IntelliJ IDEA was a good modern IDE, with these kind of industrial core features like hot reloading handled easy?

The problem is, that I really don't want to hot reload my application on every change I make to the files! Because then it will be continuously hot reloading, which will break the application most of the time. Just so unnecessary and wasting resources. I want to hot reload always when I manually save a file, which is a standard for so many other editors. There has to be a solution for this problem, because people want reasonable hot reload for their development.



Solution 1:[1]

As far as I understand, your issue is that you want the spring server to reload automatically whenever you make changes and then manually save them. Right? if the that is the case, follow my steps and hopefully you will get what desire.

1. include the spring-boot-devtools dependency

Maven

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

Gradle

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

2. enable “Make project automatically” in the compiler preferences for automatic restarts to work.

enter image description here

3. enable the compiler.automake.allow.when.app.running registry setting in IntelliJ. You can access the registry in IntelliJ using the shortcut Shift+Command+A, then searching for registry.

enter image description here


The 3rd step will make building your project (make project) automatic when you save you changes manually.

======================================================================== These steps will enforce spring server to reboot once changes has been saved manually via your IDE. However, you need to refresh your browser every time you make a change even though the server is rebooted. To enforce your browser to refresh automatically as well, you need an extension installed in your browser called Live Reload. Check this link http://livereload.com/extensions/. the link will show you how to install this extension depends on your browser.

Solution 2:[2]

Solution 3:[3]

Here's a simple workflow that works well for me in IDEA Ultimate Edition and does not restart parts of the application when the code is hot swapped:

1. Install Spring Boot Developer Tools

2. Create a proper Spring Boot run configuration

The crucial step here is to set the On 'Update' action to Hot swap classes and update trigger file if failed Settings Here's the tooltip's explanation of the various options. Specifying only Update classes or resources would work, but parts of your application would be reloaded, but much faster than if you started the application from scratch. See the Restart vs Reload section of the documentation for an explanation.
Tooltip

3. Run your Spring Boot application in debug mode Shift + F9

4. Change some java files or static content and press CTRL + F10

It will update classes and resources you just changed. For good results, disable your browser's cache to avoid seeing old versions of static resources.

5. Editing templates

If you're using templating engines, the documentation provides instructions about how to reload them without restarting the container

6. (Optional) Trigger a browser refresh with LiveReload

Spring Boot Developer Tools contain a LiveReload server which helps you trigger browser reloads whenever the content changes.

Solution 4:[4]

I am using the Below Version of Community Edition

IntelliJ IDEA 2021.2.2(Community Edition)

And Below Are the Steps I performed to Hot Reload on Manual Save.

Step 1 added spring-boot-dev-tools dependency in Maven dependency pom.xml

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

Step 2
Compiler Configuration for picking build Automatically

Step 3
Advance Compiler Setting for Restart on Manual Save

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 karel
Solution 3
Solution 4 user2498328