title: What is the lifecycle of spring bean?
body: <p>I am confused about the lifecycle of Spring. </p>
  
  <pre><code>XmlBeanFactory beanFactory 
  = new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
  </code></pre>
  
  <p>Whether the above snippet of codes creates the object or not?</p>
  
  <p>If the above answer is true. </p>
  
  <p>a) Then, for the bean where scope is "singleton" get the object which was created during the above snippet of code. Am i right or wrong?</p>
  
  <p>b) For the case where scope is "prototype", whether the created object was unused. Because, the container always return new object.</p>
  
  <pre><code>XmlBeanFactory beanFactory 
  = new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
  </code></pre>
  
  <p>Whether the above snippet of codes creates the object or not?</p>
  
  <p>If the answer is false, </p>
  
  <p>How the spring framework validates whether the bean definition is correct or not.</p>
  
  <p><strong><code>From the answer of Henry</code></strong></p>
  
  <p><code>Usually, singleton beans are created when the context starts. This can be changed with the lazy-init or default-lazy-init attributes.</code></p>
  
  <p><code>Prototype beans are only created when needed.</code></p>
  
  <p><code>Only syntactically, there might still be errors when the bean is instantiated, for example if a required property is not provided.</code></p>