susie_derkins
Sep 8th, 2004, 05:29 PM
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:
public class Foo {
public Foo() {System.out.println("Foo.Foo");}
}
The definition file:
<?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>
I load this file with the following code:
InputStream is;
is = ClassLoader.getSystemClassLoader().getResourceAsSt ream("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:
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
Is something wrong with this code?
Thanks,
Susie.
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:
public class Foo {
public Foo() {System.out.println("Foo.Foo");}
}
The definition file:
<?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>
I load this file with the following code:
InputStream is;
is = ClassLoader.getSystemClassLoader().getResourceAsSt ream("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:
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
Is something wrong with this code?
Thanks,
Susie.