How to change the way Spring Boot serves static files?

后端 未结 2 1393
萌比男神i
萌比男神i 2021-01-14 06:50

After using JHipster on a couple of new projects recently (Highly recommended ! Amazing work !), I am trying to back-port some of the concepts into an older webapp, essentia

2条回答
  •  花落未央
    2021-01-14 07:07

    You can try following configuration. The idea should be pretty straight forward. It does register artifacts in assets directory.

    public class AppMvcConfiguration extends WebMvcConfigurerAdapter {
    
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          // Including all static resources.
    
          registry.addResourceHandler("/assets/**", 
                      "/css/**", 
                      "/img/**",
                      "/js/**"
                 ).addResourceLocations("/assets/",
                      "/css/", 
                      "/img/",
                      "/js/"
          ).resourceChain(true)
           .addResolver(new PathResourceResolver());
    
           super.addResourceHandlers(registry);
      }
    }
    

提交回复
热议问题