diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 0c0a06247f..841023b55b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -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.