title: Add a Servlet Filter in a Spring Boot application
body: <p>I'd like to have <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-etag">ETag suport</a>. For this purpose there is a <code>ShallowEtagHeaderFilter</code> which does all the work. How can I add it without declaring it in my <code>web.xml</code> (which actually does not exist, because I somehow got by without it so far)?</p>
  
  <p>P.S. I use Spring Boot 1.1.4</p>
  
  <p>P.P.S. Here's a full solution</p>
  
  <pre class="lang-java prettyprint-override"><code>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;
      }
  
  }
  </code></pre>