In my Spring Boot project I have the following structure:
- src
- main
- java
- resources
- static
- css
- js
- img
-
Finally found the solution. It was much simpler than I thought.
Since I'm using war packaging I can use webapp's default behaviour. Everything under source folders trigger a restart, but resources under webapp are fetched at runtime, so there is no need to reload anything.
I just placed my static content under /webapp/static and then added the resource handler:
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
}
Just don't use the default Spring Boot placement for statics (basically anything under resources) and you'll be fine.