4

I am using a dependency as:

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

The devtools work fine when I make changes to my .java files but doesn't work when I make changes in my static files(.html files). Also, the change is not seen when I reload the page. I have to restart the application to see the changes. And it is quite a time consuming to restart the app every time I make a few small changes.

Let's_Create
  • 2,963
  • 3
  • 14
  • 33
pujan kc
  • 444
  • 1
  • 5
  • 11

2 Answers2

2

In spring-boot-maven-plugin in pom.xml add the following configuration:

<configuration>
    <addResources>true</addResources>
</configuration>

The above will work if you starting the app from the command line. However, please see this post for more details on this: Refreshing static content with Spring MVC and Boot

fiveelements
  • 3,649
  • 1
  • 17
  • 16
  • But this didn't work for me. I am starting the app from an IDE(eclipse). The same devtool is working in a different project but not in this one. – pujan kc Jul 24 '19 at 17:40
  • Follow the link provided. You'll find many solutions. This is a duplicate question by the way. – fiveelements Jul 24 '19 at 17:41
2

With Spring Boot 3.1.2, set the following properties in application-dev.properties:

spring.web.resources.static-locations=file:src/main/resources/static/
spring.devtools.restart.additional-paths=file:src/main/resources/static/

I added these configurations in a dev profile because in production static content will be served from the classpath. Remember to activate the correct profile.

What it does:

  • Devtools will restart the service whenever there are changes in the static directory and trigger a live reload. It pairs great with live-reload browser extensions.
  • Static resources are served from the file system instead of the classpath. It allows serving up-to-date static files without needing to rebuild the project. That way you do not the need to configure your IDE to rebuild on every save which may be a little slow, depending on the project.

I set this up for a web project built using Vite, (vite build --watch) and dumping all output in src/main/resources/static/ Spring Boot Devtools picks up the changes almost immediately.

This answer is the same that I wrote here https://stackoverflow.com/a/76997426/8474661