Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Spring Framework Interview Questions and Answers

Ques 6. What do you mean by Auto Wiring?

The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has five modes.

  • no
  • byName
  • byType
  • constructor
  • autodetect

Is it helpful? Add Comment View Comments
 

Ques 7. What is IOC or inversion of control?

As the name implies Inversion of control means now we have inverted the control of creating the object from our own using new operator to container or framework. Now it's the responsibility of container to create object as required.

We maintain one xml file where we configure our components, services, all the classes and their property. We just need to mention which service is needed by which component and container will create the object for us. This concept is known as dependency injection because all object dependency (resources) is injected into it by framework.
Example:
In this example CreateNewStockAccont class contain getter and setter for newBid and container will instantiate newBid and set the value automatically when it is used. This whole process is also called wiring in Spring and by using annotation it can be done automatically by Spring, refereed as auto-wiring of bean in Spring.

Is it helpful? Add Comment View Comments
 

Ques 8. Explain Bean-LifeCycle.

Spring framework is based on IOC so we call it as IOC container also So Spring beans reside inside the IOC container. Spring beans are nothing but Plain old java object (POJO).

Following steps explain their life cycle inside container:
  1. Container will look the bean definition inside configuration file (e.g. bean.xml).
  2. Using reflection container will create the object and if any property is defined inside the bean definition then it will also be set.
  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 before the properties for the Bean are set.
  6. If an init() method is specified for the bean, it will be called.
  7. If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
  8. If the Bean definition in the Configuration file contains a 'destroy-method' attribute, then the corresponding method definition in the Bean class will be called.

Is it helpful? Add Comment View Comments
 

Ques 9. What are the different modules in Spring framework?

  • The Core container module
  • Application context module
  • AOP module (Aspect Oriented Programming)
  • JDBC abstraction and DAO module
  • O/R mapping integration module (Object/Relational)
  • Web module
  • MVC framework module

Is it helpful? Add Comment View Comments
 

Ques 10. what is Bean Factory, have you used XMLBeanFactory?

BeanFactory is factory Pattern which is based on IOC design principles. It is used to make a clear separation between application configuration and dependency from actual code.

XmlBeanFactory is one of the implementation of bean Factory which we have used in our project.
org.springframework.beans.factory.xml.XmlBeanFactory is used to create bean instance defined in our xml file.
BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"));
Or
ClassPathResource resorce = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(resorce);

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook