-
Notifications
You must be signed in to change notification settings - Fork 41.2k
SpringApplicationShutdownHook throws ClassCastException when use log4j2 #26953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you able to provide a sample application (either a zip file or a GitHub repo) that we can use to reproduce the problem? |
Hi. Here it is. This application has been created via initializer. There are only main class and custom log4j configuration. Upd link to zip: build directory was removed to decrease archive size. |
Thanks for the sample, @tormozzg. I've reproduced the problem. We end up with a
Log4j swallows this exception and returns a |
@tormozzg You can avoid the problem by disabling Log4j's own shutdown hook (which it enables by default):
This will ensure that Log4j is shut down after the context has been closed so you won't lose any logging that happens during shutdown. We'll have to see what we can do to avoid the need for |
Thanks. It helped. |
Previously, Log4j2's own shutdown hook was only disabled when Log4j2 detected javax.servlet.Servlet on the classpath and, therefore, determined that it was running in a web application. In an application without Servlet on the classpath, this could lead to both Log4j2's shut down hook and and logging system's shutdown handler both stopping Log4j2. This could result in a failure as the second attempt at stopping would result in reinitialization which would fail as the JVM is already shutting down. This commit introduces a new Log4j2 PropertySource implementation, registered via META-INF/services, that sets the log4j.shutdownHookEnabled property to false. This will ensure that Log4j2's own shutdown hook is disabled by default whenever Spring Boot is on the classpath and not just in Servlet-based web applications. Fixes spring-projectsgh-26953
Hi.
I get the exception when try to replace logging module with log4j2 in spring boot version 2.5.1.
This error doesn't occur in 2.4.7 and below.
I also tried to downgrade log4j to 2.13.x, but it didn't help.
Dependencies
log4j2.xml
The text was updated successfully, but these errors were encountered: