Wrap depends-on exception for specifically requested top-level bean

Closes gh-32470
This commit is contained in:
Juergen Hoeller 2024-04-24 13:41:48 +02:00
parent 4a10bc3288
commit 387e34d881
2 changed files with 11 additions and 1 deletions

View File

@ -316,6 +316,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"'" + beanName + "' depends on missing bean '" + dep + "'", ex);
}
catch (BeanCreationException ex) {
if (requiredType != null) {
// Wrap exception with current bean metadata but only if specifically
// requested (indicated by required type), not for depends-on cascades.
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Failed to initialize dependency '" + ex.getBeanName() + "' of " +
requiredType.getSimpleName() + " bean '" + beanName + "'", ex);
}
throw ex;
}
}
}

View File

@ -949,7 +949,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
for (String weaverAwareName : weaverAwareNames) {
getBean(weaverAwareName);
beanFactory.getBean(weaverAwareName, LoadTimeWeaverAware.class);
}
// Stop using the temporary ClassLoader for type matching.