Skip to content

Commit 0a5c21f

Browse files
committed
Remove ServletContextPropertySource from environment on Log4j shutdown
1 parent a68eae6 commit 0a5c21f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@
6666
import org.springframework.core.Conventions;
6767
import org.springframework.core.Ordered;
6868
import org.springframework.core.annotation.Order;
69+
import org.springframework.core.env.ConfigurableEnvironment;
6970
import org.springframework.core.env.Environment;
7071
import org.springframework.util.Assert;
7172
import org.springframework.util.ClassUtils;
7273
import org.springframework.util.CollectionUtils;
7374
import org.springframework.util.ResourceUtils;
7475
import org.springframework.util.StringUtils;
76+
import org.springframework.web.context.support.StandardServletEnvironment;
7577

7678
/**
7779
* {@link LoggingSystem} for <a href="https://logging.apache.org/log4j/2.x/">Log4j 2</a>.
@@ -449,7 +451,13 @@ private LevelConfiguration getLevelConfiguration(Level level) {
449451

450452
@Override
451453
public Runnable getShutdownHandler() {
452-
return () -> getLoggerContext().stop();
454+
return () -> {
455+
Environment environment = (Environment)getLoggerContext().getObject(ENVIRONMENT_KEY);
456+
if (environment instanceof ConfigurableEnvironment configurableEnvironment) {
457+
configurableEnvironment.getPropertySources().remove(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME);
458+
}
459+
getLoggerContext().stop();
460+
};
453461
}
454462

455463
@Override

0 commit comments

Comments
 (0)