首页 > 解决方案 > spring boot地址和端口号问题

问题描述

我正在寻找此处报告的问题的可能根本原因(SO 线程) - 无法在 eclipse 中启动 Tomcat v9.0 服务器

在摆弄上面(与上面提到的线程无关)时,不小心,而不是

server.port=8080

我把下面放在我的 application.properties 文件中

server.address=8080

当我尝试启动服务器时,在我意识到错字之前一直收到此错误。

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 8080 was already in use

当我用“端口”替换“地址”时,一切正常。

问题:是预期行为还是已知缺陷或可能的新缺陷?如果它是一个新缺陷,我在哪里可以在 Spring Community 上报告它?

更新

根据 github 问题跟踪器https://github.com/spring-projects/spring-boot/issues/21101上的评论,它现在已修复,修复将在下一个版本 2.2.7 中发布

标签: springspring-bootapplication.properties

解决方案


Spring Boot 无法将服务器绑定到无效地址 8080。

默认消息是

Web 服务器无法启动。8080 端口已被使用

你可以尝试设置

server.addresss=9090

你会得到同样的信息。

错误消息只是误导。

消息生成于PortInUseFailureAnalyzer

并在这里抛出 PortInUseException:

public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        try {
            addPreviouslyRemovedConnectors();
            Connector connector = this.tomcat.getConnector();
            if (connector != null && this.autoStart) {
                performDeferredLoadOnStartup();
            }
            checkThatConnectorsHaveStarted();
            this.started = true;
            logger.info("Tomcat started on port(s): " + getPortsDescription(true) + " with context path '"
                    + getContextPath() + "'");
        }
        catch (ConnectorStartFailedException ex) {
            stopSilently();
            throw ex;
        }
        catch (Exception ex) {
            if (findBindException(ex) != null) {
                throw new PortInUseException(this.tomcat.getConnector().getPort());
            }
            throw new WebServerException("Unable to start embedded Tomcat server", ex);
        }
        finally {
            Context context = findContext();
            ContextBindings.unbindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());
        }
    }
}

推荐阅读