Skip to content

Commit 387e34d

Browse files
committed
Wrap depends-on exception for specifically requested top-level bean
Closes gh-32470
1 parent 4a10bc3 commit 387e34d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

+10
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ else if (requiredType != null) {
316316
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
317317
"'" + beanName + "' depends on missing bean '" + dep + "'", ex);
318318
}
319+
catch (BeanCreationException ex) {
320+
if (requiredType != null) {
321+
// Wrap exception with current bean metadata but only if specifically
322+
// requested (indicated by required type), not for depends-on cascades.
323+
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
324+
"Failed to initialize dependency '" + ex.getBeanName() + "' of " +
325+
requiredType.getSimpleName() + " bean '" + beanName + "'", ex);
326+
}
327+
throw ex;
328+
}
319329
}
320330
}
321331

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory b
949949
// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
950950
String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
951951
for (String weaverAwareName : weaverAwareNames) {
952-
getBean(weaverAwareName);
952+
beanFactory.getBean(weaverAwareName, LoadTimeWeaverAware.class);
953953
}
954954

955955
// Stop using the temporary ClassLoader for type matching.

0 commit comments

Comments
 (0)