Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Developer Tools Auto restart doesn't work in IntelliJ

Started spring-boot with spring-boot-devtools recently in IntelliJ and spent couple of hours trying to figure out why IntelliJ would not pick up my changes and auto restart embedded tomcat.

Information at this link didn't help either: https://dzone.com/articles/spring-boot-application-live-reload-hot-swap-with

like image 703
Samir Shaik Avatar asked Dec 01 '18 10:12

Samir Shaik


People also ask

How do I automatically restart my Spring Boot?

Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. This can be a useful feature when working in an IDE as it gives a very fast feedback loop for code changes. By default, any entry on the classpath that points to a folder will be monitored for changes.


2 Answers

In order to make it work, you need to:

1)Have devtools enable in maven or gradle. In maven it looks like :

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

2)In IntellijIDEA: go in settings(ctrl +alt+s) -> Build,Execution,Deployment -> compiler, check "Build project automatically"

3)In IntellijIDEA: press ctrl+shift+a then type "registry" and click on it. Then enable the option "compiler.automake.allow.when.app.running".

4) RESTART intellijIDEA !! I lost few hours because of this :/

It should now be working.

Please note that:

-You don't need additional-paths or trigger-file for this to work as intended.

-If you are using the maven launch parameter -Dspring-boot.run.fork=false to enable debugging, then devtools are disabled, so it should not reboot on code change.

-in the yaml file, you need to use quotes for parameters coming from the pom. If you don't, the project will run the first time and then fail on reboot.

spring:
  profiles:
    active: '@spring.profiles.active@'

IT WORKS WITH INTELLIJIDEA COMMUNITY EDITION, it's worth the caps as many answers say it works only with ultimate...

like image 190
Harald Avatar answered Sep 28 '22 04:09

Harald


The issue was resolved by changing the name of the project from spring-boot to spring-boot-xxx (basically anything but spring-boot).

If you read the documentation carefully here's what is mentioned:

When deciding if an entry on the classpath should trigger a restart when it changes, DevTools automatically ignores projects named spring-boot, spring-boot-devtools, spring-boot-autoconfigure, spring-boot-actuator, and spring-boot-starter.

Building the project using Ctrl+F9 automatically triggers a restart. If you wish to automatically trigger as soon as a class file is saved you can follow the hot-swap link provided in the question.

Spring Boot also has an option to trigger restart when a specific file changes and that can be configured in application.properties using following property

spring.devtools.restart.trigger-file=

Hope this helps someone save time.

like image 40
Samir Shaik Avatar answered Sep 28 '22 03:09

Samir Shaik