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

2

15

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

Tread answered 1/12, 2018 at 10:10 Comment(0)
G
17

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...

Globuliferous answered 11/5, 2020 at 3:0 Comment(2)
great but it seems like it has a fixed time to restart not when a modification is made .Loram
Great answer but the "compiler.automake.allow.when.app.running" option has been moved to advanced settings as "Allow auto-make to start even if developed application is currently running". Checking that, after add the dependency should work.Screen
T
7

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.

Tread answered 1/12, 2018 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.