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

前端 未结 2 1992
一生所求
一生所求 2021-01-24 05:53

In my Spring Boot project I have the following structure:

- src
  - main
    - java
    - resources
      - static
        - css
        - js
        - img
    -         


        
相关标签:
2条回答
  • 2021-01-24 06:13

    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.

    0 讨论(0)
  • 2021-01-24 06:31

    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.

    0 讨论(0)
提交回复
热议问题