【发布时间】:2014-11-26 20:46:39
【问题描述】:
我想要ETag suport。为此,有一个ShallowEtagHeaderFilter 可以完成所有工作。我如何添加它而不在我的web.xml 中声明它(它实际上不存在,因为到目前为止我不知何故没有它)?
附:我使用 Spring Boot 1.1.4
附言这是一个完整的解决方案
package cuenation.api;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.ShallowEtagHeaderFilter;
import javax.servlet.DispatcherType;
import java.util.EnumSet;
@Configuration
public class WebConfig {
@Bean
public FilterRegistrationBean shallowEtagHeaderFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new ShallowEtagHeaderFilter());
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
registration.addUrlPatterns("/cue-categories");
return registration;
}
}
【问题讨论】:
-
嗯,您的问题包含解决方案的链接。只需向下滚动几行。
-
@zeroflagL 向下滚动几行:这里还是 spring 文档中?我没有关注你!
-
@zeroflagL 哦,我明白你的意思了。但我的问题是我没有任何 xml 配置。见my custom initializer。我做错了什么?
-
如何将 ShallowEtagHeaderFilter 添加到项目中,以便它可以评估并将 Etag 发送到浏览器。我们需要覆盖任何东西吗?
标签: spring annotations servlet-filters spring-boot