Sha*_*shi 11 java lifecycle spring
我对Spring的生命周期感到困惑.
XmlBeanFactory beanFactory
= new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
Run Code Online (Sandbox Code Playgroud)
上面的代码片段是否创建了对象?
如果上述答案是真的.
a)然后,对于范围为"singleton"的bean,获取在上面的代码片段中创建的对象.我是对还是错?
b)对于范围是"原型"的情况,创建的对象是否未使用.因为,容器总是返回新对象.
XmlBeanFactory beanFactory
= new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
Run Code Online (Sandbox Code Playgroud)
上面的代码片段是否创建了对象?
如果答案是假的,
spring框架如何验证bean定义是否正确.
From the answer of Henry
Usually, singleton beans are created when the context starts. This can be changed with the lazy-init or default-lazy-init attributes.
Prototype beans are only created when needed.
Only syntactically, there might still be errors when the bean is instantiated, for example if a required property is not provided.
BeanFactory
没有在启动时预先实例化单身人士ApplicationContext
.所以,即使你的bean是非懒惰和单身,它也不会被创建.
prototype
bean是按需创建的,每次你要求一个原型bean时你都会获得一个新的实例.但是一旦在自动装配期间使用了这样的bean,将永远使用相同的实例.
随着ApplicationContext
所有单身人士的热切创造和原型豆只需要.
归档时间: |
|
查看次数: |
6133 次 |
最近记录: |