Reload static content spring boot application

browser-sync, gulp, spring, spring-boot, static

Solution

Add the following to src/main/resources/application.properties:

spring.web.resources.static-locations[0]=file:src/main/resources/static/
spring.web.resources.static-locations[1]=classpath:/static/

The "file:" causes the content to be reloaded on refreshing the browser, see related issue.

Alternatively, the file resource locations can be discovered at runtime and added programmatically.

See also documentation and tutorial.

Note that prior to Spring Boot 2.4, the property was called "spring.resources.static-locations".

Problem

I am using Netbeans and I am developing my first web application using spring boot. I was keeping my HTML, js, CSS in "webapp" folder and then I refactored my project and I put all static content in `/resources/static`. Since then, I have to rebuild my project every time because the static content isn't reloaded. Can I easily bypass this problem if I'll use browser-sync plugin for Gulp?

Original source

Related problems