springspring-bootspring-boot-devtools

Spring Boot Dev Tools Restart Not Working


I'm trying to get restart working with Spring Boot DevTools. I have been following the instructions provided here: https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

I am using gradle and included this in my build.gradle file:

bootJar {
    excludeDevtools = false
}

I create the jar file and run the jar file:

java -jar app.jar

I am able to connect to the running application through Intellij. When I make a change I can see in the Intellij console that the updated classes are uploaded to the running process. And in the logs of the running process, I see the process attempts to restart. However, the process quits and spits out this log:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.BootApplication]; nested exception is java.io.FileNotFoundException: class path resource [com/example/ExampleService.class] cannot be opened because it does not exist.

ExampleService is the class I modified.

I attempted to google the heck out of this, but could find nothing. I looked at many tutorials online, but could find nothing.

Has anyone encountered this or has anything I can try, would be much appreciated.


Solution

  • The issue is based on how compilation of a file works. When you compile a file, it first deletes the already compiled file and then adds a new one. During this process, file system watcher consider it as two different updates (deletion of file and addition of a new file) if the poll time is too low. And deletion of file triggers deletion of file from the remote application and tries to restart the application without the file you changed and therefore, you get this error.

    I was facing the similar problem but solved it by adding following in application.properties

    spring.devtools.restart.pollInterval=10s
    

    You can change the pollInterval that suits you