title: How to define Servlet filter order of execution in Spring Boot application
body: <p>I am trying to set the order of execution of 2 filters in my spring boot application which have same url mapping. I have tried using 2 filter registration beans in my main Application class as below but that did not work. I want the <code>authorizationFilter</code> to be hit first then the <code>validationFilter</code>. But it is always hitting ONLY <code>validationFilter</code> when both are configured. If I comment out the <code>validationFilter</code>, it hits <code>authorizationFilter</code>.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Bean
  public FilterRegistrationBean authorizationFilter(){
      FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
      filterRegBean.setFilter(authorizationFilter);
      List&lt;String&gt; urlPatterns = new ArrayList&lt;String&gt;();
      urlPatterns.add("/v1/*");
      filterRegBean.setUrlPatterns(urlPatterns);
      return filterRegBean;
  }
  
  @Bean
  public FilterRegistrationBean validationFilter(){
      FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
      filterRegBean.setFilter(validationFilter);
      List&lt;String&gt; urlPatterns = new ArrayList&lt;String&gt;();
      urlPatterns.add("/v1/*");
      filterRegBean.setUrlPatterns(urlPatterns);
      return filterRegBean;
  }
  </code></pre>
  
  <p>I have also tried introducing <code>web.xml</code> and converting the executable jar to war file.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;web-app&gt;   
  &lt;filter&gt;
      &lt;filter-name&gt;authorizationFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;com.security.filter.AuthorizationFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;authorizationFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/v1/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  &lt;filter&gt;
      &lt;filter-name&gt;validationFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;com.security.validation.ValidationFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;validationFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/v1/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>But the application doesn't seem to recognize the web.xml, as it hits only the validation filter with the configuration above.
  I appreciate any inputs in resolving this.
  Thanks</p>