title: Spring Not Calling PostConstruct method when XML config is used but works when Java Config is used
body: <p>I have following class</p>
  <pre><code>
  import com.ujjwal.model.Speaker;
  import com.ujjwal.repository.SpeakerRepository;
  
  import javax.annotation.PostConstruct;
  import java.util.List;
  
  public class SpeakerServiceImpl implements SpeakerService {
  
      private SpeakerRepository repository;
  
      public SpeakerServiceImpl() {
          System.out.println(&quot;inside No Args Constructor&quot;);
      }
  
      public SpeakerServiceImpl(SpeakerRepository repository) {
          System.out.println(&quot;inside Args Constructor&quot;);
          this.repository = repository;
      }
  
      @PostConstruct
      private void initialize() {
          System.out.println(&quot;Post Construct Init&quot;);
      }
  
      public void setSpeakerRepository(SpeakerRepository repository) {
          System.out.println(&quot;In setSpeakerRepository&quot;);
          this.repository = repository;
      }
  
      public List&lt;Speaker&gt; findAll() {
          return repository.findAll();
      }
  
  }
  </code></pre>
  <p>And following is my xml config file</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&gt;
  
      &lt;bean name=&quot;speakerRepository&quot;
            class=&quot;com.ujjwal.repository.HibernateSpeakerRepositoryImpl&quot;/&gt;
  
      &lt;!--&lt;bean name=&quot;speakerRepositoryUj&quot;
            class=&quot;com.ujjwal.repository.UjjwalSpeakerRepositoryImpl&quot;/&gt;--&gt;
  
      &lt;bean name=&quot;speakerService&quot;
          class=&quot;com.ujjwal.service.SpeakerServiceImpl&quot;&gt;
      &lt;constructor-arg index=&quot;0&quot; ref=&quot;speakerRepository&quot;/&gt;
      &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  <p>Also, I made sure that my pom.xml has javax.annotation libraray and maven included it in external libraries.</p>
  <p>Now, following is my Application class which has main method:</p>
  <pre><code>import com.ujjwal.service.SpeakerService;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class Application {
  
      public static void main(String args[]) {
  
          ApplicationContext appContext =
                  new ClassPathXmlApplicationContext(&quot;applicationContext.xml&quot;);
          SpeakerService service = appContext.getBean(&quot;speakerService&quot;, SpeakerService.class);
  
          System.out.println(service.findAll().get(0).getFirstName());
      }
  }
  </code></pre>
  <p>Now, I am not seeing print statement of initialize method in my output. And following is the output:</p>
  <pre><code>inside Args Constructor
  Ujjwal
  </code></pre>
  <p>But I get the print statement of initialize method when instead of using xml config I use Java Configuration for Beans.</p>
  <p>Can anyone please explain what is happening here?</p>