我正在尝试使用 CorsConfiguration 在应用程序中设置缓存控制。理想情况下,当我在DHC或Rest Api
中调用PostMan
时,我应该获得Cache-Control Max Age 3600,但是我的响应低于以下要求:
缓存控制:无缓存,无存储,max-age = 0,必须重新验证
有人请帮助我。预先感谢。
以下是我的Application.java class
@EnableCaching
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class); }
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setMaxAge(3600L);
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("POST");
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
}