我在初始上下文加载期间实例化 bean 时发现了一个奇怪的弹簧行为。我有一个加载大型 ML 模型的 bean。由于内存不足,bean 无法实例化抛出 java OutOfMemoryError
java heap space 异常。但这不会阻止应用程序实例化,而是继续加载应用程序。
为什么会这样?这是预期的吗?
检查弹簧AbstractAutowireCapableBeanFactory
,
try {
// Mark this bean as currently in creation, even if just partially.
beforeSingletonCreation(beanName);
// Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.
instance = resolveBeforeInstantiation(beanName, mbd);
if (instance == null) {
bw = createBeanInstance(beanName, mbd, null);
instance = bw.getWrappedInstance();
}
}
finally {
// Finished partial creation of this bean.
afterSingletonCreation(beanName);
}
它用注释默默地消化异常// Finished partial creation of this bean.
这不会影响应用程序的稳定性吗?为什么会这样设计?
还是我错过了什么?