Scenario: spring-boot-starter-parent v2.2.1.RELEASE Method on @component class 'Foo' annotated with @PreDestroy throws an ExceptionInInitializerExceptionError

Expected: Logs to contain exception message and stack trace to easily identify the cause of the exception

Actual: Logs only contain "Destroy method on bean with name 'foo' threw an exception: java.lang.ExceptionInInitializerExceptionError" without any further details

Comment From: nosan

Hi @Woodz,

org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor (org.springframework.context.annotation.CommonAnnotationBeanPostProcessor) is not a part of Spring Boot codebase.

If you take a look at this part of the code, you will find there is a possibility to enable stack trace details via the DEBUG level.

    @Override
    public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
        LifecycleMetadata metadata = findLifecycleMetadata(bean.getClass());
        try {
            metadata.invokeDestroyMethods(bean, beanName);
        }
        catch (InvocationTargetException ex) {
            String msg = "Destroy method on bean with name '" + beanName + "' threw an exception";
            if (logger.isDebugEnabled()) {
                logger.warn(msg, ex.getTargetException());
            }
            else {
                logger.warn(msg + ": " + ex.getTargetException());
            }
        }
        catch (Throwable ex) {
            logger.warn("Failed to invoke destroy method on bean with name '" + beanName + "'", ex);
        }
    }

Comment From: nosan

You can enable DEBUG level with:

logging.level.org.springframework.context.annotation.CommonAnnotationBeanPostProcessor=debug

Comment From: Woodz

You can enable DEBUG level with:

ini logging.level.org.springframework.context.annotation.CommonAnnotationBeanPostProcessor=debug

Thanks @nosan! Sorry for the incorrect bug report

Comment From: wilkinsona

Thanks for helping out, @nosan.