title: How do I exclude a specific URL in a filter in Spring?
body: <p>I have a basic application filter config that looks like this:</p>
  
  <pre><code>@Configuration
  public class ApplicationFilterConfig {
  
      /**
      * Check if user is logged in
      */
      @Bean
      public FilterRegistrationBean applicationFilterRegistration() {
  
          // created a collections that need logins to be validated.
          ArrayList&lt;String&gt; urlPatterns = new ArrayList&lt;String&gt;();
          urlPatterns.add("/home");
          urlPatterns.add("/about");
          urlPatterns.add("/contact");
          // ... 
  
          LoginFilter loginFilter = new LoginFilter();
          FilterRegistrationBean registration = new FilterRegistrationBean(); 
          registration.setFilter(loginFilter);
          registration.setUrlPatterns(urlPatterns);
          registration.setOrder(1);
          return registration;
  
      } 
  
  
  }
  </code></pre>
  
  <p>However, the list <code>urlPatterns</code> grows to be very long, even when using the star annotation (e.g. <code>/employees/*</code>). The main reason why I don't just use <code>/*</code> is because I don't want to require login validation for my login page. If I did, it'd create an infinite loop of redirects. </p>
  
  <p>Does the <code>FilterRegistrationBean</code> class allow you to apply a filter to all URL patterns <em>except</em> certain patterns? </p>
  
  <p>I could put everything except the login page in a directory and set my URL pattern to be <code>/subdirectory/*</code> but that adds an unnecessary level of depth to every file in my webapp. </p>