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