title: Sharing common Spring Boot configuration between projects
body: <p>The app I'm working on has a maven dependency on a common module containing a dozen <code>spring-boot</code> <code>@Configuration</code> beans specifying datasources, LDAP contexts, security modules, property sources etc which I often want to suppress.</p>
  
  <p>My app and this common module are part of a <code>spring-boot</code> <code>maven</code> multi-module project. My sub-project needs about 6 of the 12 configuration beans. </p>
  
  <p>I have got quite a long way using <code>@Import</code> and <code>@SpringBootApplication#exclude</code> and <code>@ImportAutoConfiguration</code>:</p>
  
  <pre><code>@Import({PropertySpringConfig.class,
          LdapConfig.class,
          SecurityConfig.class,
          JpaDataConfiguration.class,
          RestConfiguration.class,
          WebConfigurer.class})
  @SpringBootApplication(exclude = {
          RefDataSourceConfig.class,
          ElasticsearchAutoConfiguration.class,
          CamelAutoConfiguration.class,
          ElasticsearchDataAutoConfiguration.class})
  public class MyRestApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(MyRestApplication.class, args);
      }
  
  }
  </code></pre>
  
  <p>and a test configuration bean that all my JPA tests import (I have others, e.g. for REST tests):</p>
  
  <pre><code>@Configuration
  @OverrideAutoConfiguration(enabled = false)
  @ImportAutoConfiguration(value = {
          CacheAutoConfiguration.class,
          JpaRepositoriesAutoConfiguration.class,
          DataSourceAutoConfiguration.class,
          DataSourceTransactionManagerAutoConfiguration.class,
          HibernateJpaAutoConfiguration.class,
          TransactionAutoConfiguration.class,
          TestDatabaseAutoConfiguration.class,
          TestEntityManagerAutoConfiguration.class })
  public class TestJpaConfiguration {}
  </code></pre>
  
  <p>The whole codebase was set up with Spring 1.3.x. I upgraded it to Spring 1.4.x. </p>
  
  <p>Take for example one of the datasources, a configuration bean in the shared dependency - I don't need it, and it prevents Spring Boot autoconfiguration because it's marked with <code>@Primary</code> (possibly unnecessarily). </p>
  
  <p>I don't want Spring Boot in my sub-project to see it when it runs autoconfiguration, but how do I share it from the common module with the other Spring Boot sub-projects that do need it?</p>
  
  <ol>
  <li><p>I could split it out into its own maven project and only have it as a dependency in the sub-projects that needed it. But there are 11 other similar configuration beans! It could be seen as overkill although I like this approach - but I have 5 colleauges to convince. </p></li>
  <li><p>I can just struggle on using <code>@SpringBootApplication#excludes</code> for the code and <code>@ImportAutoConfiguration</code> for the tests - but then I miss out on the Spring Boot benefits like <code>@DataJpaTest</code> or <code>@JsonTest</code> test slices </p></li>
  <li><p>I could repeat the configuration beans in each project where they are needed - a bit of cut &amp; paste - but I like this option the least.</p></li>
  <li><p>Is there a 4?</p></li>
  </ol>