Spring Boot triggers full restart instead of reload on changes over static files

故事扮演 提交于 2019-12-02 07:57:57

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.

Did you also read the chapter for the "LiveReload"? You'll need to make sure that your LiveReload Server is started from the SpringBoot-Devtools. You can also use the browser plugin from LiveReload.com. Or you could use the Plugin from the Chrome Web Store. See Chapter LiveReload for more details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!