title: Load Configuration Bean Dynamically
body: <p>I'm making a spring boot app that needs to have basic authentication or Oauth2 depending on a property i have defined.</p>
  
  <p>The problem is that if I created two classes with @configuration the application doesn't start, and if I just leave one and in the configure method I add an if to configure the HttpSecurity object i fails when try to hit the endpoint with basic authentication.</p>
  
  <p>I  try to register bean dynamically this way:</p>
  
  <pre><code>@Bean
  public ResourceServerSecurityConfig oauthConfig(){
      if(isOauthEnabled){
          return new ResourceServerSecurityConfig();
      }else{
          return null;
      }
  }
  @Bean
  public BasicSecurityConfig basicConfig(){
      if(isOauthEnabled){
          return new BasicSecurityConfig ();
      }else{
          return null;
      }
  }
  </code></pre>
  
  <p>But the configuration is not loaded. 
  Any hints on how this can be archived??</p>