title: Spring: how AnnotationConfigWebApplicationContext could not overwrite later beans?
body: <p>I have a web application that use Sring IoC framework. 
  I use the Java configuration for Spring, and I only use <code>@Configuration</code> annoted module definition (no DI related tags elsewhere in the code). </p>
  
  <p>The Spring registry is built on web application start-up thanks to (a bit modified version of) Spring context loader listener, and the <strong>contextConfigLocation</strong> param in web.xml configured to point to the @Configuration annotated class.</p>
  
  <p>All that is good and I get a AnnotationConfigWebApplicationContext.</p>
  
  <p>Now, I want to have plugins in my application, that will have their own <code>@Configuration</code> annotated configuration classes, and will use some of the main application services. <strong>BUT</strong> I don't want to have main application to be modified to load these new modules.</p>
  
  <p>So, I thought that I could simply use the package searching of annotated class for that, but now, it seems that I can use two beans with the same type, even if they have different ids, and clearly AnnotationConfigWebApplicationContext doc states that:</p>
  
  <blockquote>
    <p>Note: In case of multiple @Configuration classes, later <code>@Bean</code> definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra Configuration class. </p>
  </blockquote>
  
  <p>I don't want that, because modules should be able to contribute alternative version of services, not (alwways) override existing one - especcially if I want to have a "moduleDef" bean.</p>
  
  <p>I tried to use differents approach on that, but the hierachy of Context and related services is just to big for me.</p>
  
  <p>So, does anybody know how I could reach my goal ? </p>
  
  <p>Thanks</p>