Spring 5 - How to provide static resources

后端 未结 2 1894
灰色年华
灰色年华 2021-01-05 05:12

I am trying provide static resources in my web application and I tried:

@SuppressWarnings(\"deprecation\")
@Bean
WebMvcConfigurerAdapter configurer(){
    re         


        
2条回答
  •  我在风中等你
    2021-01-05 05:21

    Just to add from the answer of @alfcope above:

    The same objective can be achieved by directly extending WebMvcConfigurationSupport as suggested in the documentation

    It seems like extending WebMvcConfigurationSupport serves the purpose of @EnableWebMvc and allows selectively override any desired default implementation and in this case addResourceHandlers. So the example code can be

    @Configuration
    public class WebConfig extends WebMvcConfigurationSupport {
    
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                    registry.addResourceHandler("/resources/**")
                            .addResourceLocations("/public", "classpath:/static/")
                            .setCachePeriod(31556926);
            }
    
    }
    

提交回复
热议问题