Java and Advance java Training, Spring Hibernate training  Flow Us  Twitter For  Connect with Google  Blog  LinkedIn  Ph: +91 98 7171 6360
+91 99 1143 1185
E-mail:  contact@DelhiGuru.in

Spring Frequently Asked Questions

These questions are the most important for interview and written by industry expert.

Explain Bean lifecycle in Spring framework?

  1. The spring container finds the bean’s definition from the XML file and instantiates the bean.
  2. Using the dependency injection, spring populates all of the properties as specified in the bean definition.
  3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
  4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
  5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called.
  6. If an init-method is specified for the bean, it will be called.
  7. Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.
 

What is Spring ?

Spring is a lightweight inversion of control(IoC) and aspect-oriented container framework.
 
 

What is XMLBeanFactory?

BeanFactory has many implementations in Spring. But one of the most useful one is org.springframework.beans.factory.xml.XmlBeanFactory, which loads its beans based on the definitions contained in an XML file. To create an XmlBeanFactory, pass a java.io.InputStream to the constructor. The InputStream will provide the XML to the factory. For example, the following code snippet uses a java.io.FileInputStream to provide a bean definition XML file to XmlBeanFactory.
BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"));
To retrieve the bean from a BeanFactory, call the getBean() method by passing the name of the bean you want to retrieve.
MyBean myBean = (MyBean) factory.getBean("myBean")