【问题标题】:Caused by: java.net.BindException: Address already in use: bind引起:java.net.BindException:地址已在使用:绑定
【发布时间】:2019-02-28 17:13:26
【问题描述】:

我正在尝试通过单击 Run as -> Spring Boot App 来运行 Spring Boot 应用程序。我收到的错误是:

原因:java.net.BindException:地址已在使用:绑定

当我使用 netstat 命令时,我看到下面没有进程 ID:

netstat -na | find "8080"

TCP    0.0.0.0:8080   0.0.0.0:0    LISTENING

TCP    [::]:8080      [::]:0       LISTENING

注意 - 我在 windows 机器上运行我的代码

如何杀死这些进程?

【问题讨论】:

  • 在windows机器上添加o标志来获取进程ID(如netstat -nao | find "8080")然后你可以用Taskkill杀死它

标签: windows spring-boot process taskkill


【解决方案1】:

试试lsof -i命令,它应该列出pid之间的网络连接。 或者更好的 lsof -i :8080

【讨论】:

  • 您好,我忘了提及我正在我的 Windows 机器上运行此代码。所以,我无法运行上面的命令 lsof -i
【解决方案2】:

您可以通过在application.properties 中提供类似server.port=4567 的内容来更改应用程序的端口号。

或

您可以按照http://www.codeman.in/blog/windows-kill-process-by-port-number-157 中提到的步骤来杀死在端口号上运行的进程:-

【讨论】:

    【解决方案3】:

    很可能正在使用“8080”,您可以结束任务/关闭应用程序,或者只是更改 Spring boot 使用的默认端口。您可以通过多种方式实现,application.properties 就是其中之一。

    【讨论】:

      【解决方案4】:
      try {
                  SpringApplication.run(Application.class, args);
              } catch     (org.springframework.boot.web.server.PortInUseException e) {
      //Runtime.exec("pkil")..
      //or
      SpringApplication.run(Application.class, otherargs);
      //SpringApplication.run(Application.class, new String[]{"--server.port=8444"});
      //when invoked recursively it is a port rebalancer for port usage among port pool with server as from client for startup stage via application restarts within many busy ports which are used before or without querying.
      
      }
      

      【讨论】:

        猜你喜欢
        • 2013-12-02
        • 1970-01-01
        • 1970-01-01
        • 2015-10-30
        • 2014-08-11
        • 2013-09-08
        • 2012-04-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多