场景:双击jar就启动了,没有任何弹窗。再从其他地方启动就报端口占用
报错信息
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
描述:
Web服务器无法启动。端口8080已经在使用中。
行动:
识别并停止在端口8080上侦听的进程,或将此应用程序配置为在另一个端口上侦听。
解决办法
打开cmd
PS E:\IdeaProjects\spring-boot-02\boot-09-features-profile\target> netstat -ano | findstr 8080
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 10772
TCP [::]:8080 [::]:0 LISTENING 10772
PS E:\IdeaProjects\spring-boot-02\boot-09-features-profile\target> taskkill /t /f /pid 10772
成功: 已终止 PID 10772 (属于 PID 16440 子进程)的进程。
PS E:\IdeaProjects\spring-boot-02\boot-09-features-profile\target> netstat -ano | findstr 8080
PS E:\IdeaProjects\spring-boot-02\boot-09-features-profile\target>
taskkill | netstat | findstr |
/pid <processID> 指定要终止的进程的进程 ID。 | -a 显示计算机正在侦听的所有活动 TCP 连接以及 TCP 和 UDP 端口。 | | 管道符,把前面netstat 运行的结果传如findstr 应该是的,文档里没见到,不过作用是这样的 |
/t 结束指定进程以及由该进程启动的任何子进程。 | -n 但是,显示活动的 TCP 连接,地址和端口号以数字表示,并且不会尝试确定名称。 | 搜索8080 |
/f 指定强制结束进程。 对于远程进程,此参数将被忽略。所有远程进程都被强制结束。 | -o 显示活动的 TCP 连接,并包括每个 (PID) 的进程 ID。 可以在”进程”选项卡上找到基于 PID 的应用程序Windows 任务管理器。 此参数可以与 -a、 -n 和 -p 结合使用。 |
windows命令指南 https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/tasklist