How can I programmatically configure Spring's @Configuration annotations?
<p>Specifically, I would like to be able share configuration classes by instantiating them and including them. Where you would normally do this:</p>

<pre><code>@Configuration
@Import({SharedConfiguration.class})
public class MyAppContext extends WebMvcConfigurerAdapter {
  //stuff
}

@Configuration
@ComponentScan("com.example")
public class SharedConfiguration {
  //stuff
}
</code></pre>

<p>I would like to do this:</p>

<pre><code>@Configuration
public class MyAppContext extends WebMvcConfigurerAdapter {
  public SharedConfiguration sharedConfig(){
    return new SharedConfiguration("com.example");
  }

  //stuff
}

@Configuration
public class SharedConfiguration {
  public SharedConfiguration(String package){
    //tell Spring to scan package
  }
}
</code></pre>

<p>The reason for this is that I need to be able to tell the shared component doing the scan what package to look at. It will different depending on what project it is being used in.</p>

<p>EDIT:</p>

<p>To provide some additional context, I'm trying to make a general-use configuration for setting up Hibernate and EHCache using our external configuration provider that several projects can use. I'm certainly open to other methods to doing this, but this seemed like the most logical path to me. I'm sure there's ~something~ in Spring that I can fiddle with to say, "Here! Scan this path when Spring initializes you!" instead of hard-coding it into an annotation.</p>