我对 Spring 的生命周期感到困惑。
XmlBeanFactory beanFactory
= new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
上面的代码片段是否创建了对象?
如果上面的答案是真的。
a) 然后,对于作用域为“单例”的 bean,获取在上述代码片段中创建的对象。我是对还是错?
b) 对于范围为“原型”的情况,创建的对象是否未被使用。因为,容器总是返回新对象。
XmlBeanFactory beanFactory
= new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
上面的代码片段是否创建了对象?
如果答案是假的,
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.