Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 474
Ville Miekk-oja Avatar asked Mar 30 '17 22:03

Ville Miekk-oja


People also ask

How can I reload my Spring Boot without having any changes?

5 Answers. Show activity on this post. Add spring-boot-devtools module to your project, which includes LiveReload server which can be used to trigger a browser refresh whenever a resource has been changed. You can download browser extensions from livereload.com.

How do I enable hot swap in IntelliJ?

Reload all files Recompilation happens automatically if the Build project before reloading classes option is enabled in Settings/Preferences | Build, Execution, Deployment | Debugger | HotSwap. If this option is disabled, you need to recompile the files before reloading (Build | Recompile Ctrl+Shift+F9 ).

Does Spring Boot have hot reload?

There are several options for hot reloading. The recommended approach is to use spring-boot-devtools as it provides additional development-time features such as support for fast application restarts and LiveReload as well as sensible development-time configuration (e.g. template caching).


1 Answers

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.

like image 98
Faisal Julaidan Avatar answered Oct 12 '22 23:10

Faisal Julaidan