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
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.
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).
- Container will look the bean definition inside configuration file (e.g. bean.xml).
- Using reflection container will create the object and if any property is defined inside the bean definition then it will also be set.
- If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean's ID.
- If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
- If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called before the properties for the Bean are set.
- If an init() method is specified for the bean, it will be called.
- If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
- 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.
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
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.
Most helpful rated by users:
- What is Spring?
- What are the advantages of Spring framework?
- What are features of Spring?
- What are the types of Dependency Injection Spring supports?
- Please describe the basic modules of Spring Framework.