Skip to content

Commit 4b3550e

Browse files
committed
fix: don't auto-start jetty service for negative port
1 parent 207c8f5 commit 4b3550e

File tree

1 file changed

+18
-19
lines changed
  • spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty

1 file changed

+18
-19
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,23 @@ public void start() throws WebServerException {
145145
return;
146146
}
147147
this.server.setConnectors(this.connectors);
148-
if (!this.autoStart) {
149-
return;
150-
}
151148
try {
152149
this.server.start();
153-
for (Handler handler : this.server.getHandlers()) {
154-
handleDeferredInitialize(handler);
155-
}
156-
Connector[] connectors = this.server.getConnectors();
157-
for (Connector connector : connectors) {
158-
try {
159-
connector.start();
150+
if (this.autoStart) {
151+
for (Handler handler : this.server.getHandlers()) {
152+
handleDeferredInitialize(handler);
160153
}
161-
catch (IOException ex) {
162-
if (connector instanceof NetworkConnector networkConnector) {
163-
PortInUseException.throwIfPortBindingException(ex, networkConnector::getPort);
154+
Connector[] connectors = this.server.getConnectors();
155+
for (Connector connector : connectors) {
156+
try {
157+
connector.start();
158+
}
159+
catch (IOException ex) {
160+
if (connector instanceof NetworkConnector networkConnector) {
161+
PortInUseException.throwIfPortBindingException(ex, networkConnector::getPort);
162+
}
163+
throw ex;
164164
}
165-
throw ex;
166165
}
167166
}
168167
this.started = true;
@@ -212,11 +211,11 @@ private String getContextPath() {
212211
return null;
213212
}
214213
return this.server.getHandlers()
215-
.stream()
216-
.map(this::findContextHandler)
217-
.filter(Objects::nonNull)
218-
.map(ContextHandler::getContextPath)
219-
.collect(Collectors.joining(" "));
214+
.stream()
215+
.map(this::findContextHandler)
216+
.filter(Objects::nonNull)
217+
.map(ContextHandler::getContextPath)
218+
.collect(Collectors.joining(" "));
220219
}
221220

222221
private ContextHandler findContextHandler(Handler handler) {

0 commit comments

Comments
 (0)