Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么即使bean未能实例化,Spring仍继续初始化上下文?_Java_Spring_Autowired_Spring Bean - Fatal编程技术网

Java 为什么即使bean未能实例化,Spring仍继续初始化上下文?

Java 为什么即使bean未能实例化,Spring仍继续初始化上下文?,java,spring,autowired,spring-bean,Java,Spring,Autowired,Spring Bean,我在初始上下文加载期间实例化bean时发现了一种奇怪的spring行为。我有一个加载大型ML模型的bean。由于内存不足,bean无法实例化抛出javaOutOfMemoryErrorjava堆空间异常。 但这不会阻止应用程序实例化,而是继续加载应用程序 为什么会发生这种情况?这是预期的吗 已检查弹簧AbstractAutowireCapableBeanFactory try { // Mark this bean as currently in creation, even if ju

我在初始上下文加载期间实例化bean时发现了一种奇怪的spring行为。我有一个加载大型ML模型的bean。由于内存不足,bean无法实例化抛出java
OutOfMemoryError
java堆空间异常。 但这不会阻止应用程序实例化,而是继续加载应用程序

为什么会发生这种情况?这是预期的吗

已检查弹簧
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);
}
它用注释
//悄悄地消化异常,完成了这个bean的部分创建。

这不会影响应用程序的稳定性吗?为什么设计成这样?

还是我遗漏了什么?

注意这里没有catch语句!此外,
OutOfMemoryError
不是一个
异常
,因此它不会被标准的常规
catch(异常e)
捕获

有了这个
finally
子句,
Throwable
就不会被捕获。它必须在别的地方被捕获(消化)

为什么春天继续它的工作?它基于web服务器,而不是独立的专用应用程序,为什么要立即停止工作?并非所有的异常都是关键的,甚至错误有时也可以(很少)从中恢复。程序员的职责是确保所有“他的”一次性软件得到正确处理,而不是Spring的