Asked by
Amit Dubey
in
Computers & Technology
at
10:06 PM on December 08, 2008
ayisha's Answer
BeanFactory has many implementations in Spring. But one of the most useful one is org.springframework.beans.factory.x ml.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");
Sources:
http://faqs.javabeat.net/ spring/spring-interview-questions-f aqs-2.php
Answered at
11:42 PM on December 08, 2008
Read all answers