windows启微服务端口被占用情况的排查与解决方法

问题如下

复制代码
Failed to start connector [Connector[HTTP/1.1-19200]]

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-19200]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:256) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:198) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
	at com.sgcc.xjgc.platform.material.MaterialAppMain.main(MaterialAppMain.java:24) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_261]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_261]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.4.RELEASE.jar:2.0.4.RELEASE]
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1020) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	... 18 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
	at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_261]
	at sun.nio.ch.Net.bind(Net.java:444) ~[na:1.8.0_261]
	at sun.nio.ch.Net.bind(Net.java:436) ~[na:1.8.0_261]
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:225) ~[na:1.8.0_261]
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) ~[na:1.8.0_261]
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-embed-core-8.5.32.jar:8.5.32]
	... 19 common frames omitted

根据错误信息,问题出现在尝试启动服务器时,遇到了端口已被占用的情况(Address already in use: bind)。这意味着尝试绑定的端口 19200 已经被另一个进程占用了。

解决方案

1. 查找占用端口的进程

首先,需要找到哪个进程占用了端口 19200。在 Windows 上,可以使用以下命令来查找占用端口的进程:

cmd 复制代码
netstat -ano | findstr 19200

这将列出所有监听在端口 19200 的连接及其对应的进程 ID。

然后,使用以下命令根据进程 ID 查找对应的进程名称:

cmd 复制代码
tasklist | findstr <进程ID>

例如,如果端口被进程 ID 为 1234 的进程占用,命令如下:

cmd 复制代码
tasklist | findstr 1234
2. 终止占用端口的进程

如果确认该进程不是必要的,可以终止它。在 Windows 上,可以使用以下命令杀死进程:

cmd 复制代码
taskkill /F /PID <进程ID>

例如,如果进程 ID 为 1234,命令如下:

cmd 复制代码
taskkill /F /PID 1234
3. 更改应用端口

如果无法终止占用端口的进程,或者希望避免此类冲突,可以更改应用程序监听的端口。在 Spring Boot 应用中,在 application.propertiesapplication.yml 文件中更改端口号:

示例 application.properties
properties 复制代码
server.port=19201
示例 application.yml
yaml 复制代码
server:
  port: 19201
4. 检查防火墙设置

确保防火墙设置没有阻止端口 19200 的使用。如果是防火墙问题,可以暂时关闭防火墙进行测试:

cmd 复制代码
netsh advfirewall set allprofiles state off

测试完成后,请记得重新开启防火墙:

cmd 复制代码
netsh advfirewall set allprofiles state on

示例步骤

  1. 查找占用端口的进程

    cmd 复制代码
    netstat -ano | findstr 19200
  2. 查找对应进程名称

    cmd 复制代码
    tasklist | findstr <进程ID>
  3. 终止占用端口的进程

    cmd 复制代码
    taskkill /F /PID <进程ID>
  4. 更改应用端口

    properties 复制代码
    server.port=19201
  5. 重新启动应用

    确保更改端口后重新启动应用。

相关推荐
码界奇点6 分钟前
解密AI语言模型从原理到应用的全景解析
人工智能·语言模型·自然语言处理·架构
alphaTao1 小时前
LeetCode 每日一题 2025/11/3-2025/11/9
windows·leetcode
七宝大爷7 小时前
多GPU并行计算互联架构解析:NVLink的诞生与SLI CrossFire的落幕
架构·nvlink·sli
习惯就好zz8 小时前
WSL2 安装Ubuntu卡在安装进度0%无响应问题解决
linux·windows·ubuntu·wsl·wsl2
忙碌5448 小时前
AI大模型时代下的全栈技术架构:从深度学习到云原生部署实战
人工智能·深度学习·架构
仰望—星空11 小时前
MiniEngine学习笔记 : CommandListManager
c++·windows·笔记·学习·cg·direct3d
阿里云云原生13 小时前
阿里云微服务引擎 MSE 及 API 网关 2025 年 10 月产品动态
阿里云·微服务·云原生·云计算
喜欢吃豆14 小时前
GraphRAG 技术教程:从核心概念到高级架构
人工智能·架构·大模型
ue星空14 小时前
Windows内核函数使用
windows
虚伪的空想家14 小时前
华为A800I A2 arm64架构鲲鹏920cpu的ubuntu22.04 tls配置直通的grub配置
ubuntu·华为·架构·虚拟化·kvm·npu·国产化适配