title: Spring bean property population through init method
body: <p>I have one question regarding spring beans initialization. What would be the scneario when we are populating bean property through init methods. Have a look at given below code snippet. Here I am populating super class bean property list through init method.</p>
  
  <p>1) Super class Bean :</p>
  
  <pre><code>public class Super  {
      private List&lt;String&gt; list = new ArrayList&lt;String&gt;();
      public void setList(List&lt;String&gt; list) {
          this.list = list;
      }
      public void init(){
       System.out.println("Super init called");
       populateList();
       System.out.println("Super list"+list.size());
      }
      public void populateList(){
          list.add("A");
          list.add("B");
      }
      public List&lt;String&gt; getList() {
          return list;
      }
  }
  </code></pre>
  
  <p>2) Bean 2 :</p>
  
  <pre><code>public class Sub extends Super {
      public static void main(String[] args) {
          ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/appXml/init-test.xml");
          Sub utils = (Sub)ctx.getBean("sub");
  
          System.out.println("Sub list:::"+utils.getList().size());
          for(String s : utils.getList()){
              System.out.println("Value::::" +s);
          }
      }
  }
  </code></pre>
  
  <p>3) Spring-context xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
      &lt;bean id = "super" class = "com.hitesh.springtest.Super" init-method="init"&gt;
      &lt;/bean&gt;
      &lt;bean id = "sub" class = "com.hitesh.springtest.Sub"&gt;&lt;/bean&gt;    
      &lt;/beans&gt;
  </code></pre>
  
  <p>4) Output :
      Super init called
      Super list2
      Sub list:::0</p>
  
  <p>My question is when super class is getting initialized by container the init() is called. In this method the list object is populated. Now when sub class instantiation is completed why we are getting list size as 0, as we are referring to very same list object which has been populated in super bean initialization. Can somebody explain this ?</p>