Skip to content

Commit 4ee260a

Browse files
committed
Merge branch '2.5.x' into 2.6.x
Closes gh-29454
2 parents d28942e + 1c6471e commit 4ee260a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,7 +72,9 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
7272

7373
private final List<Valve> engineValves = new ArrayList<>();
7474

75-
private List<LifecycleListener> contextLifecycleListeners = getDefaultLifecycleListeners();
75+
private List<LifecycleListener> contextLifecycleListeners = new ArrayList<>();
76+
77+
private List<LifecycleListener> serverLifecycleListeners = getDefaultServerLifecycleListeners();
7678

7779
private Set<TomcatContextCustomizer> tomcatContextCustomizers = new LinkedHashSet<>();
7880

@@ -105,7 +107,7 @@ public TomcatReactiveWebServerFactory(int port) {
105107
super(port);
106108
}
107109

108-
private static List<LifecycleListener> getDefaultLifecycleListeners() {
110+
private static List<LifecycleListener> getDefaultServerLifecycleListeners() {
109111
AprLifecycleListener aprLifecycleListener = new AprLifecycleListener();
110112
return AprLifecycleListener.isAprAvailable() ? new ArrayList<>(Arrays.asList(aprLifecycleListener))
111113
: new ArrayList<>();
@@ -119,6 +121,9 @@ public WebServer getWebServer(HttpHandler httpHandler) {
119121
Tomcat tomcat = new Tomcat();
120122
File baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir("tomcat");
121123
tomcat.setBaseDir(baseDir.getAbsolutePath());
124+
for (LifecycleListener listener : this.serverLifecycleListeners) {
125+
tomcat.getServer().addLifecycleListener(listener);
126+
}
122127
Connector connector = new Connector(this.protocol);
123128
connector.setThrowOnFailure(true);
124129
tomcat.getService().addConnector(connector);

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,7 +124,9 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
124124

125125
private List<Valve> contextValves = new ArrayList<>();
126126

127-
private List<LifecycleListener> contextLifecycleListeners = getDefaultLifecycleListeners();
127+
private List<LifecycleListener> contextLifecycleListeners = new ArrayList<>();
128+
129+
private List<LifecycleListener> serverLifecycleListeners = getDefaultServerLifecycleListeners();
128130

129131
private Set<TomcatContextCustomizer> tomcatContextCustomizers = new LinkedHashSet<>();
130132

@@ -173,7 +175,7 @@ public TomcatServletWebServerFactory(String contextPath, int port) {
173175
super(contextPath, port);
174176
}
175177

176-
private static List<LifecycleListener> getDefaultLifecycleListeners() {
178+
private static List<LifecycleListener> getDefaultServerLifecycleListeners() {
177179
ArrayList<LifecycleListener> lifecycleListeners = new ArrayList<>();
178180
if (!NativeDetector.inNativeImage()) {
179181
AprLifecycleListener aprLifecycleListener = new AprLifecycleListener();
@@ -192,6 +194,9 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
192194
Tomcat tomcat = new Tomcat();
193195
File baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir("tomcat");
194196
tomcat.setBaseDir(baseDir.getAbsolutePath());
197+
for (LifecycleListener listener : this.serverLifecycleListeners) {
198+
tomcat.getServer().addLifecycleListener(listener);
199+
}
195200
Connector connector = new Connector(this.protocol);
196201
connector.setThrowOnFailure(true);
197202
tomcat.getService().addConnector(connector);

0 commit comments

Comments
 (0)