Saturday, May 26, 2012

Spring Framework-Introduction to BeanFactory



A Bean Factory is an implementation of factory design. The responsibility of that class is to create or dispense beans .A bean factory is general-purpose factory. The bean factory simply instantiate and delivery of application objects.  A bean factory knows about many objects with in application .It is able to create association between  collaborating object as they instantiate and remove the burden of configuration from the bean itself . It also takes part in life cycle of bean making calls to custom initialization and destruction methods, if those methods are defined.


è The most commonly used beanfactory implementation is- –org.springframework.beans.factory.xml.XmlBeanFactory  . it loads its bean based definition contain in xml file.
è To create an XmlBeanFactory , mast pass an instance of org.springframework.core.io.Resource to the constructor.the Resource object provide xml to the beanfactory.
Ex.
       BeanFactory fact=new xmlBeanFactory(new     FileSystemResource(“filename.xml”));
  This line of code tells to the bean factory to read the bean definitions from xml file.but the bean factory does not instantiate  the beans just yet.the bean will not instantiate until they are needed.
è To retrieve the bean from a bean factory ,call getBean() method by passing the bean id as argument.
                BeanClass BC=(BeanClass) fact.getBean(“beanId”);
  When getBean() method is called the factory instantiate the bean and set the bean’s   property using ID.


For Further Reading,
General, Java, spring

0 comments:

Post a Comment


 

Site Status

Man Behind Technical Today

Hello, I am Navin Bansal. I am a student of MCA in Rajsthan Institute of Engineering and Technology and owner of this blog. I share my view and ideas among people.