Skip to content

Make Devtools file detection more resilient across application restarts #19543

@Artur-

Description

@Artur-

To reproduce the problem

  1. go to https://vaadin.com/start
  2. click "download" to get the Spring Boot starter
  3. unzip and run mvn
  4. When app has started, open http://localhost:8080 to verify that the main view with a button is shown
  5. While the app is running, do mv target/classes/com/packagename/myapp/MainView.class . ; sleep 2 ; mv MainView.class target/classes/com/packagename/myapp/MainView.class
  6. Refresh the browser and you will see
Could not navigate to ''
Reason: Couldn't find route for ''

instead of the expected view

Note that sleep 2 is dependent on how fast your machine is. On my recent Macbook Pro, 2 is a suitable time to sleep.

If the delay is too short, then devtools will wait for both the removal of the old class and addition of the new class before restarting and the view will be available. If the delay is too long, then devtools will first restart once after the removal and then notice the new class later and restart again. Thus the view will also be available in the end although missing on one reload in between.

When the time is just right, devtools will fail to notice that the class has been added and will just restart the application without the class

Adjusting

spring.devtools.restart.poll-interval

and

spring.devtools.restart.quiet-period

to some degree helps this but is no generic solution as working and broken values are dependent on the speed and load of the development machine.

Now this is not just academic but at least IntelliJ IDEA apparently works like this: first the class is removed and then a new one is created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions