title: spring.main.allow-bean-definition-overriding=true is ignored and ConflictingBeanException is thrown
body: <p>I am working on a spring-boot application with version <strong>2.2.0</strong>.</p>
  <p>I wanted to override a bean, which spring-boot provides by default. So I tried <code>spring.main.allow-bean-definition-overriding=true</code> in my <code>workflow.properties</code> file.</p>
  <p>The code is same in both java files, one whose bean is provided by default and the one which I have created. The only difference is, the java file that I have created will load the resource which I provide it, instead of loading the default resource by default bean(from spring-boot).</p>
  <p>I am loading <code>workflow.properties</code> like this in my main Application which extends <code>org.springframework.boot.web.servlet.support.SpringBootServletInitializer</code>:</p>
  <pre><code>@Override
  protected SpringApplicationBuilder configure( SpringApplicationBuilder application )
  {
      application.application().setDefaultProperties( getProperties() );
      return application.sources( WorkflowServiceApplication.class );
  }
  
  public static void main( String[] args )
      {
          // SpringApplication.run( WorkflowServiceApplication.class, args );
          new SpringApplicationBuilder( WorkflowServiceApplication.class ).properties( &quot;spring.config.name:workflow&quot; )
                                                                          .build()
                                                                          .run( args );
      }
  
  static Properties getProperties()
  {
      Properties props = new Properties();
  
      props.put( &quot;spring.config.name&quot;, &quot;workflow&quot; );
  
      props.put( &quot;spring.config.location&quot;, &quot;../conf/&quot; );
      return props;
  }
  </code></pre>
  <p>But I'm still getting the same <code>ConflictingBeanException</code></p>
  <pre><code>Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'stencilSetResource' for bean class [org.flowable.ui.modeler.rest.app.StencilSetResource] conflicts with existing, non-compatible bean definition of same name and class [com.myApplication.workflow.workflowservice.controllers.StencilSetResource]
      at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:349) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
      at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:287) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
      at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:290) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:587) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
      ... 15 common frames omitted
  </code></pre>
  <p>After checking in<a href="https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/" rel="nofollow noreferrer"> spring-boot documentation</a>, I think that by default bean definition overriding is false, but why does the overriding not work even if I set it to true in my properties file?</p>
  <p><strong>Edit:</strong>
  After going through <a href="https://docs.spring.io/spring-boot/docs/2.1.12.RELEASE/reference/html/howto-spring-boot-application.html" rel="nofollow noreferrer">this documentation</a>, it looks like the configuration that tells <code>Environment</code> to read properties from <code>workflow.properties</code> instead of <code>application.properties</code> happens after <code>ApplicationContext</code> is refreshed. Also a couple of properties like <code>spring.main.*</code> are read and loaded to <code>Environment</code> before <code>ApplicationContext</code> refresh happens. The link suggests to load property source into <code>Environment</code> by implementing <code>EnvironmentPostProcessor</code>, so I'll try that and see how it goes.</p>
  <p><strong>Edit 2:</strong>
  Okay so I tried the approach given in documentation link in above edit:</p>
  <pre><code>@Order( Ordered.LOWEST_PRECEDENCE )
  public class CustomEvironmentPostProcesor implements EnvironmentPostProcessor
  {
      private static final String DEFAULT_MY_FRAMEWORK_PROPERTIES = &quot;workflowProperties&quot;;
      private static final String DEFAULT_MY_FRAMEWORK_PROPERTIES_LOCATION = &quot;/workflow.properties&quot;;
  
      private PropertiesPropertySourceLoader propertySourceLoader = new PropertiesPropertySourceLoader();
  
      @Override
      public void postProcessEnvironment( ConfigurableEnvironment environment,
                                          SpringApplication application )
      {
          Resource workflowProperties = new ClassPathResource( DEFAULT_MY_FRAMEWORK_PROPERTIES_LOCATION );
          List&lt;PropertySource&lt;?&gt;&gt; propertySource;
          try
          {
              propertySource = propertySourceLoader.load( DEFAULT_MY_FRAMEWORK_PROPERTIES, workflowProperties );
              if( propertySource != null )
              {
                  environment.getPropertySources().addLast( propertySource.get( 0 ) );
              }
          }
          catch( IOException e )
          {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>I can see my <code>workflow.properties</code> getting loaded in <code>Environment</code> instance passed in <code>postProcessEnvironment</code> method.</p>
  <p>But still, I get the same exception.</p>