title: Overriding a custom WebSecurityConfigurerAdapter causes both to be instantiated
body: <p>Here's my situation: I have a project that has is using Spring Security. All is working well. </p>
  
  <p>I have this:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      public AuthenticationFailureHandler getAuthenticationFailureHandler(){
           return new PlainFailureHandler();
      }
  
      @Override
      protected void configure(HttpSecurity httpSec) throws Exception {
          AuthFilter filter = new AuthFilter(getAuthenticationFailureHandler());
          filter.setAuthenticationManager(authenticationManagerBean());
          httpSec.addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class);        
      }
  
  }
  </code></pre>
  
  <p>And so far, everything is great. Now, I have a second project that is built on top of this first project. </p>
  
  <p>In it, I need to override the AuthenticationFailureHandler. </p>
  
  <p>I created a new class in my second project, and it looks similar:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
  public class NewProjectSecurityConfig extends SecurityConfig {
  
      @Override
      public AuthenticationFailureHandler getAuthenticationFailureHandler() {
          return new NewProjectAuthenticationFailureHandler();
      }
  }
  </code></pre>
  
  <p>And now my problem is that Spring is instantiating both of them, resulting in two filters. I can add an <code>@Order(1)</code> to make sure that one gets done before the other, but what I really want is <em>only</em> to use the second config, and somehow tell Spring to use it <em>instead</em> of the first. I'm still new with Spring, so I apologize if I've missed a 'bigger picture' item. I'm also unable to change Project 1, so I can't just remove the original config and duplicate it.</p>
  
  <p>NOTE: I am not using config files at all, this is all done programatically. </p>