What is BeanFactory in Spring framework?

What is BeanFactory in Spring framework?

A BeanFactory is an implementation fo the factory design patterns. The BeanFactory is a root interface for accessing a Spring bean container. This is the basic client view of a bean container; further interfaces such as ListableBeanFactory and ConfigurableBeanFactory are available for specific purposes. 

This interface is implemented by objects that hold a number of bean definitions, each uniquely identified by a String name. Depending on the bean definition, the factory will return either an independent instance of a contained object.

The point of this approach is that the BeanFactory is a central registry of application components, and centralizes configuration of application components (no more do individual objects need to read properties files.
There are several implementations of BeanFactory in Spring. But the most useful is

org.springframework.beans.factory.xml.XmlBeanFactory, which loads its bean based on the definitions contained in an XML file.

BeanFactory f = new XmlBeanFactory(new FileInputStream(\"beans.xml\"));

Date:2031-01-09 00:00:00

Post Your Answers

User Email:

User Name:

Related spring sub Links

spring sub interview questions and answers for experienced and fresher