Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot hotswap with Intellij IDE

I have a spring boot application running fine with Intellij IDE. i.e i started the Application class that has the main method which delegates to SpringApplication.run. Everything works great except hotswap. When I change the source, I am forced to re-start the application. Even If I start the application in debug mode, I dont see hotswap working. I could see that Intellij's Debug settings have hotswap enabled.

My observation shows that when I run the springboot application, classpath used is my

 /projects/MyProject/classes/production/.... 

Files under classes/production are not getting updated when I change the code. Intellij IDE compiles the files but does not update classes/production directory. How do I get hotswap working with IntelliJ IDE for spring-boot?

like image 794
suman j Avatar asked Apr 18 '14 13:04

suman j


People also ask

How do I enable HotSwap 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 ).

Can I use IntelliJ for Spring Boot?

IntelliJ IDEA creates a Spring Boot run configuration that you can use to run your new Spring application. If the run configuration is selected, press Shift+F10 . icon in the gutter of the SpringBootTutorialApplication. java file next to the class declaration or the main() method declaration.

Does Spring Boot support 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 (such as template caching).

How do I turn on hot deployment in Spring Boot?

Click the currently running service, and then click Edit Configurations . Click on the program you want to configure, find On 'Update' action and On frame deactivation select Update classes and resources . Click OK to implement hot deployment. After the above configuration, after modifying the code.


2 Answers

A solution that uses devTools works :

1 - Adding devtools to your project

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

2- Enabling automatic build

Open the Settings --> Build-Execution-Deployment --> Compiler and enable :

Build Project Automatically. 

3- Update the value of compiler.automake.allow.when.app.running

press ctrl+shift+A and search for the registry. In the registry, enable :

compiler.automake.allow.when.app.running 

Hope it helps !


References :

  • https://dzone.com/articles/spring-boot-application-live-reload-hot-swap-with
like image 157
Radouane ROUFID Avatar answered Sep 17 '22 21:09

Radouane ROUFID


Found out the root cause. This has nothing to do with Spring-boot. On changing my groovy source files, files were not auto-compiled.

To recompile changed files and swap them:

  • Ctrl+Shift+F9 on Windows
  • Cmd+Shift+F9 on Mac
like image 20
suman j Avatar answered Sep 19 '22 21:09

suman j