I found a strange spring behavior in instantiating the beans during initial context Loading. I had a bean that loads large ML models. Due to insufficient memory the bean failed to instantiate throwing Out java OutOfMemoryError
java heap space exception.
But this doesn't stop the application from instantiating, instead it continues to load the application.
Why does this happen? Is this expected?
checked the spring 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);
}
It digests the exception silently with comment // Finished partial creation of this bean.
Doesn't this affect the application stability? Why is it designed so?
Or am I missing something?