【问题标题】:Port 8080 is already in use端口 8080 已在使用中
【发布时间】:2021-08-04 15:10:14
【问题描述】:

该方法在没有路径变量的情况下正常工作,但是当我编写路径变量并运行应用程序时,它说端口 8080 已在使用中

@GetMapping(path="/{userId}")
public String getUser(@PathVariable String userId) {
    return "Get User Info with id "+userId;
}

【问题讨论】:

  • 它与@PathVariable 无关。这表示您已经有一个进程在同一端口上运行。我的猜测是您尝试运行一个新的,而旧的仍在运行
  • 什么是操作系统?取决于您的操作系统,您需要了解哪个应用程序拥有此端口,如果它与您的应用程序不同,您可以在 springboot application.properties [server.port=XXXX] 中更改 8080。如果您的 springboot 应用程序已经拥有它,您应该从 IDE 或命令行中终止该进程。

标签: java spring rest web-services


【解决方案1】:

首先您的问题不在于 路径变量,端口 8080 已被某些其他应用程序

使用

Linux 命令,

sudo netstat -nlap | grep 8080
sudo kill <process id>

Windows 命令

netstat -ano | findstr :8080
taskkill /PID <process id> /F

如果任何应用程序使用8080端口,它将返回进程ID。

【讨论】:

    【解决方案2】:

    在 mac 上,试试这个

    sudo lsof -i :8080
    
    # get the process id from here and run
    
    kill -9 <process_id>
    

    【讨论】:

      【解决方案3】:

      我在 Windows 上解决了

      netstat ano | findstr 8080 
      
      taskkill /F /PID <number of task>
      
      

      【讨论】:

        猜你喜欢
        • 2018-01-13
        • 2014-07-01
        • 2011-05-07
        • 2013-11-26
        • 2015-09-20
        • 2016-03-19
        • 1970-01-01
        • 1970-01-01
        • 2013-03-25
        相关资源
        最近更新 更多