Application failed to start due to an exception
org.springframework.boot.web.server.PortInUseException: Port xxxx is already in use
    at org.springframework.boot.web.server.PortInUseException.lambda$throwIfPortBindingException$0(PortInUseException.java:70)
    at org.springframework.boot.web.server.PortInUseException.lambda$ifPortBindingException$1(PortInUseException.java:85)
    at org.springframework.boot.web.server.PortInUseException.ifCausedBy(PortInUseException.java:103)
    at org.springframework.boot.web.server.PortInUseException.ifPortBindingException(PortInUseException.java:82)
    at org.springframework.boot.web.server.PortInUseException.throwIfPortBindingException(PortInUseException.java:69)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:228)
    at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.onApplicationEvent(ManagementContextAutoConfiguration.java:149)
    at org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.onApplicationEvent(ManagementContextAutoConfiguration.java:121)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)

    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
    at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:46)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
    at xxxxx.Application.main(Application.java:78)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213)
    ... 41 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1075)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234)
    ... 43 common frames omitted
Caused by: java.net.BindException: Address already in use
    at java.base/sun.nio.ch.Net.bind0(Native Method)
    at java.base/sun.nio.ch.Net.bind(Net.java:455)
    at java.base/sun.nio.ch.Net.bind(Net.java:447)
    at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
    at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:274)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:229)
    at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1227)
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1313)
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614)
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1072)
    ... 45 common frames omitted

spring-boot version 2.6.6

this issue appear occasionally service deploy in k8s

Comment From: philwebb

It looks like another application is using one of the ports that you have configured. I don't think this is a bug in Spring Boot itself, but if you're able to provide a sample that replicates the problem we can reopen the issue and take a look.

Comment From: Dr-wgy

It looks like another application is using one of the ports that you have configured. I don't think this is a bug in Spring Boot itself, but if you're able to provide a sample that replicates the problem we can reopen the issue and take a look.

ok thanks a lot, we need more time investigate

Comment From: Dr-wgy

It looks like another application is using one of the ports that you have configured. I don't think this is a bug in Spring Boot itself, but if you're able to provide a sample that replicates the problem we can reopen the issue and take a look.

this issue appear occasionally, I can't provide a sample, but our service deploy in k8s , Does CloudPlatform KUBERNETES have special logical ?

Comment From: wilkinsona

No, CloudPlatform.KUBERNETES should not have any effect on server.port and management.server.port.

I noticed above that you're using Spring Boot 2.6.x, open source support for which ended in November 2022. You should upgrade to Spring Boot 3.1.x or later. Alternatively, commercial support for older versions (including 2.6.x) is available.

Comment From: Dr-wgy

No, CloudPlatform.KUBERNETES should not have any effect on server.port and management.server.port.

I noticed above that you're using Spring Boot 2.6.x, open source support for which ended in November 2022. You should upgrade to Spring Boot 3.1.x or later. Alternatively, commercial support for older versions (including 2.6.x) is available.

We spend a lot of time upgrade to 2.6.x . In short term we don't have plan to upgrade to Spring Boot 3.1.x. I found when this Port xxxx is already in use occur, I enter service use netstat this port not exists, I'm confused about this issue, Do we have some direction about this issue ?

Comment From: wilkinsona

Even if you were using a supported version, we'd be unable to provide direction for a problem that we don't fully understand and cannot reproduce.

Comment From: Dr-wgy

I choose 60000 as management.server.port I found that my service use 60000 as ephemeral port to communicate with the mysql(redis,dns) cat /proc/sys/net/ipv4/ip_local_port_range 32700 60900 SpringBoot Separate server.port and management.server.port  result in Port xxx is already in use

So I use below 32700 port just like 30001 this issue is not exsits

Comment From: xiangtianyu

Actually, i met the same problem, i set management.server.port=${server.port} and in k8s, it start failed and report "port in used", and when i set it to management.server.port=8081, it start successfully. And even when i set to "management.server.port=8080", it still start successfully. What's the special of "management.server.port=${server.port}"?

PS: When i start my app locally, it's all ok. And in k8s env, i must set management.server.port to different port.