title: overriding bean configuration in spring
body: <p>Let's say I have two modules. One is core and another is core dependent implementation module.
  Core is a jar file for that dependent implementation module war.</p>
  
  <p>In the core I have a bean defined like</p>
  
  <pre><code>&lt;bean id="x" class="com.pokuri.X"&gt;
   &lt;property name="y" ref="y"/&gt;
   &lt;property name="z" ref="z"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>And that class has a method as follows</p>
  
  <pre><code>public class X{
  
    public void doSomeJob(){
     .......
    }   
  
  }
  </code></pre>
  
  <p>this method is being called from some core classes. Now I need to alter the logic in that doSomeJob() method of X as per my core dependent implementation. So, I create a class like this</p>
  
  <pre><code>public class ExtX extends X{
  
    @override
    public void doSomeJob(){
      // changed logic
    }
  
  }
  </code></pre>
  
  <p>and defined the bean with same id in another application context xml file like this.</p>
  
  <pre><code>&lt;bean id="x" class="com.pokuri.ExtX"&gt;
       &lt;property name="y" ref="y"/&gt;
       &lt;property name="z" ref="z"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>and we are building application context using <code>contextConfigLocation</code> context parameter in <code>web.xml</code> specifying value as <code>classpath:springfolder</code>.</p>
  
  <p>But in the core logic I am getting core bean instance only(i.e <code>X</code> instance) not <code>ExtX</code>. How can we override that bean definition and let system start using new extend bean definition?</p>
  
  <p>And I heard that with same ID in different application context files will override first loaded bean definition with later loaded bean definition. Is there any <code>priority</code> kind of attribute on bean definition to let ApplicationContext use highest priority one to consider over low priority one when beans with same ID were found.</p>