Skip to content

AbstractApplicationContext#refresh omits exception trace and cause from the log #34007

@Spikhalskiy

Description

@Spikhalskiy

This is an example of a log XmlWebApplicationContext produces when there is no certain classes in the classpath:

[03 Dec 2024 00:04:49,357][WARN ][XmlWebApplicationContext,main] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter': Cannot create inner bean '(inner bean)#736f2fb8' of type [org.springframework.web.bind.support.ConfigurableWebBindingInitializer] while setting bean property 'webBindingInitializer'
[03 Dec 2024 00:04:49,357][WARN ][ClassPathXmlApplicationContext,main] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webContext' defined in class path resource [context/bootstrap.xml]: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter': Cannot create inner bean '(inner bean)#736f2fb8' of type [org.springframework.web.bind.support.ConfigurableWebBindingInitializer] while setting bean property 'webBindingInitializer'

As you can see, this log completely omits any useful details and is not useful for tracking a root case.

The culprit is AbstractApplicationContext#refresh logging the exception in the following way:

catch (RuntimeException | Error ex ) {
				if (logger.isWarnEnabled()) {
					logger.warn("Exception encountered during context initialization - " +
							"cancelling refresh attempt: " + ex);
				}
                                //...
			}

The problem is present on all 6.x Spring versions.

The only way to trace a route cause was to put a breakpoint on the logging line in Spring code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions