Call StartupStep.end in finally block
Prior to this commit it was possible that a StartupStep was started but never ended. This was the case when an exception occured during bean initializing. To always call the method regardless of the outcome, the call to StartupStep.end has been moved to a finally block. When an exception occurs the StartupStep is also enriched with the exception class and message for diagnostic purposes. See gh-22776 Closes gh-25572
This commit is contained in:
parent
7adeb461e0
commit
74a014743a
|
@ -300,9 +300,9 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
|||
markBeanAsCreated(beanName);
|
||||
}
|
||||
|
||||
StartupStep beanCreation = this.applicationStartup.start("spring.beans.instantiate")
|
||||
.tag("beanName", name);
|
||||
try {
|
||||
StartupStep beanCreation = this.applicationStartup.start("spring.beans.instantiate")
|
||||
.tag("beanName", name);
|
||||
if (requiredType != null) {
|
||||
beanCreation.tag("beanType", requiredType::toString);
|
||||
}
|
||||
|
@ -383,12 +383,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
|||
throw new ScopeNotActiveException(beanName, scopeName, ex);
|
||||
}
|
||||
}
|
||||
beanCreation.end();
|
||||
}
|
||||
catch (BeansException ex) {
|
||||
beanCreation.tag("exception", ex.getClass().toString());
|
||||
beanCreation.tag("message", ex.getMessage());
|
||||
cleanupAfterBeanCreationFailure(beanName);
|
||||
throw ex;
|
||||
}
|
||||
finally {
|
||||
beanCreation.end();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if required type matches the type of the actual bean instance.
|
||||
|
|
Loading…
Reference in New Issue