
BeanFactory Interface
A bean factory is an implementation of the Factory design pattern. A bean factory is a general-purpose factory which creates and hold many types of beans. It is a class whose responsibility is to create and dispense beans. There are several implementations of BeanFactory in Spring. The most commonly used implementation is org.springframework.beans.factory.xml.XmlBeanFactory. The following example will show how to use the XmlBeanFactory and BeanFactory to create the beans.
Example:-
Lets take the bean TestBean which has toString() method. The code for the bean is as follows:-
package com.visualbuilder.beans; public class TestBean { |
The spring metadata file is spring-beans.xml which is in com/visualbuilder/xml folder.
<?xml version="1.0" encoding="UTF-8"?> <bean id="test" class="com.visualbuilder.beans.TestBean" /> </beans> |
The Beanfactory Interace example class is as follows:-
package com.visualbuilder.factory; import org.springframework.beans.factory.BeanFactory; import com.visualbuilder.beans.TestBean; public class BeanFactoryExample { |
Output :- On running the BeanFactoryExample.java class we have got the following output.
Bean has been called
Jun 1, 2008 1:12:28 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\eclipse\workspace\sprinexample\springtutorialexample\com\visualbuilder\xml\spring-beans.xml]
Java Discussion
- - Difference between BMT an
- - Replace getParameterValue
- - Interviewing Next week -
- - Sudoku solver
- - Setting tab order in swin



