Springers,
It was my understanding that the BeanFactory instanciates the beans defined in the config file, providing lazy-init is set to “false” and the bean is a singleton.
Now, it appears that singleton are only created by a call to factory.get Bean. Is that the right behavior or Am I missing something?
Here is a code sample:
The bean:
The definition file:Code:public class Foo { public Foo() {System.out.println("Foo.Foo");} }
I load this file with the following code:Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-lazy-init="false"> <bean id="foo" class=" Foo"> </bean> </beans>
Code:InputStream is; is = ClassLoader.getSystemClassLoader().getResourceAsStream("foo.xml"); XmlBeanFactory factory = new XmlBeanFactory(is);
I would expect that there exist an instance of Foo after the call to new XmlBeanFactory. It’s apparently not the case (I don’t see the constructor’s trace in the console).
The log file is as follow:
Is something wrong with this code?Code:DefaultXmlBeanDefinitionParser -- Loading bean definitions DefaultXmlBeanDefinitionParser -- Default lazy init 'false' DefaultXmlBeanDefinitionParser -- Default dependency check 'none' DefaultXmlBeanDefinitionParser -- Default autowire 'no' DefaultXmlBeanDefinitionParser -- Registering bean definition with id 'foo' DefaultXmlBeanDefinitionParser -- Found 1 <bean> elements defining beans
Thanks,
Susie.


Reply With Quote