title: Spring Boot auto configuration order from external dependency
body: <p>I have a problem trying to get my autoconfiguration working. I have two jars as follows, each have a spring.factories file where these two are enabled for EnableAutoConfigurationProperties.</p>
  
  <p>This configuration is in my-package-mock.jar, it depends on my-package-real.jar below:</p>
  
  <pre><code>package org.packages.package.packageA;
  @Configuration
  @AutoConfigureBefore(AutoConfigurationB.class)
  public class AutoConfigurationA {
  
      @Bean
      public MyService mockService() {
          return new MyMockService();
      }
  }
  </code></pre>
  
  <p>This configuration is in my-package-real.jar:</p>
  
  <pre><code>package org.packages.package.packageB;
  @Configuration
  @ConditionalOnMissingBean(MyService.class)
  public class AutoConfigurationB {
  
      @Bean
      public MyService realService() {
          return new MyRealService();
      }
  }
  </code></pre>
  
  <p>Now the idea is that if my-package-mock.jar is included then AutoConfigurationB will not be processed as A is ordered to be before and by the time it gets to B MyService is already defined.
  However, it does not work when used in a third project that includes these jars. It looks like the AutoConfigureOrder annotation is skipped when loading these jars from the classpath and these configurations are processed in the order the jvm loads these classes. In my particular case it does B first and at that point MyService is not yet defined and thus will instantiate the RealService bean. How can I get this to work?</p>
  
  <p>Obviously this is a small example where a @Primary annotation on the mock will do the job, but that is not what I'm looking for.</p>
  
  <p>Edit: it seems if the @SpringBootApplication annotated main is not a part of the package where these configurations are then things do work. E.g. the annotation is not in "org.packages.package" but "org.somewhereelse" then things work.</p>
  
  <pre><code>package org.packages.package;
  
  @SpringBootApplication
  public class TestApplication {
  
      public static void main(String[] args) throws Exception {
      SpringApplication.run(Collections.singletonList(TestApplication.class).toArray(), args);
      }
  }
  </code></pre>