How to enable HTTP response caching in Spring Boot

前端 未结 8 1890
我寻月下人不归
我寻月下人不归 2020-11-27 12:17

I have implemented a REST server using Spring Boot 1.0.2. I\'m having trouble preventing Spring from setting HTTP headers that disable HTTP caching.

My controller is

8条回答
  •  离开以前
    2020-11-27 13:16

    @Configuration
    @EnableAutoConfiguration
    public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
    
            registry.addResourceHandler("/resources/**")
                    .addResourceLocations("/resources/")
                    .setCachePeriod(31556926);
    
        }
    }
    

提交回复
热议问题