0

I was looking for possible root cause of the problem reported here (SO thread) - Cannot start a Tomcat v9.0 server in eclipse.

While fiddling for above (unrelated to the thread above mentioned), accidentally, instead of

server.port=8080

I put below in my application.properties file

server.address=8080

When I tried to start server I kept getting this error before I realized the typo.

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

Description:

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

When I replaced "address" with "port", all worked fine.

Question: Is it expected behavior or a known defect or a possible new defect? If its a new defect, where can I report it on Spring Community?

UPDATE

Per the comments on github issue tracker https://github.com/spring-projects/spring-boot/issues/21101, it is fixed now and the fix will be released in next release 2.2.7

Ajay Kumar
  • 2,906
  • 3
  • 23
  • 46

1 Answers1

0

Spring Boot was unable to bind the server to the invalid address 8080.

And the default message is

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

You can try to set

server.addresss=9090

and you will get the same message.

The error message is just misleading.

The message is generated in PortInUseFailureAnalyzer

And the PortInUseException is thrown here:

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());
        }
    }
}
Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
  • I understand Simon. But the question is address should not be treated as port. So can it be reported to Spring Community that it need to be fixed? – Ajay Kumar Apr 23 '20 at 15:49
  • I just filed a bug report for that issue.https://github.com/spring-projects/spring-boot/issues/21101 The point is that 8080 is a valid internet address so it may not be easy to fix – Simon Martinelli Apr 23 '20 at 15:50
  • No but I'm teaching Spring Boot for a few years now at the university and had to look at the code many times already – Simon Martinelli Apr 23 '20 at 15:52
  • Awesome. Thanks for your help in reporting it. – Ajay Kumar Apr 23 '20 at 16:11