0
votes

I am trying to run 2 Microservices projects using two instances of STS (sts-4.4.2.RELEASE). Once First project is up and running , I try to run the second project and get below error. I have specified two different ports for these 2 projects via VM Agruments :

-Dserver.port=8055

-Dserver.port=8088

Looks like 8081 port is configured in Tomcat or any other configuration internally. Could you please help/suggest.

Error log :

{"mdc":{},"timestamp":"2020-05-16 11:20:07.317","level":"ERROR","logger":"org.apache.catalina.core.StandardService","message":"Failed to start connector [Connector[HTTP/1.1-8081]]","exception":"\r\norg.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8081]]\r\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)\r\n\tat org.apache.catalina.core.StandardService.addConnector(StandardService.java:225)\r\n\tat org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:261)\r\n\tat org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:198)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:311)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:164)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)\r\n\tat org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.afterSingletonsInstantiated(ManagementContextAutoConfiguration.java:151)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)\r\n\tat org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)\r\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548)\r\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)\r\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)\r\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:307)\r\n\tat ***********)\r\nCaused by: org.apache.catalina.LifecycleException: Protocol handler start failed\r\n\tat org.apache.catalina.connector.Connector.startInternal(Connector.java:1020)\r\n\tat org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)\r\n\t... 16 common frames omitted\r\nCaused by: java.net.BindException: Address already in use: bind\r\n\tat sun.nio.ch.Net.bind0(Native Method)\r\n\tat sun.nio.ch.Net.bind(Unknown Source)\r\n\tat sun.nio.ch.Net.bind(Unknown Source)\r\n\tat sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)\r\n\tat sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)\r\n\tat org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:219)\r\n\tat org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1160)\r\n\tat org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591)\r\n\tat org.apache.catalina.connector.Connector.startInternal(Connector.java:1018)\r\n\t... 17 common frames omitted\r\n\r\n"} {"mdc":{},"timestamp":"2020-05-16 11:20:07.417","level":"ERROR","logger":"org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter","message":"\r\n\r\n***************************\r\nAPPLICATION FAILED TO START\r\n***************************\r\n\r\nDescription:\r\n\r\nThe Tomcat connector configured to listen on port 8081 failed to start. The port may already be in use or the connector may be misconfigured.\r\n\r\nAction:\r\n\r\nVerify the connector's configuration, identify and stop any process that's listening on port 8081, or configure this application to listen on another port.\r\n","exception":""}

1
Found the solution : To Change the STS Tomcat Server port: >> Go to Run configuration >> Open Spring Boot Tab >> In Override Properties section copy below command to specify the port management.server.port=8082Jeetendra

1 Answers

1
votes

Two possible reasons:
1. Tomcat is not honoring the -Dserver.port= argument. Do note that -D is a JVM startup argument that, in this case, sets the server.port system variable. If you append -Dserver.port to the end of the Tomcat startup command, it might be interpreted as a command line argument for the Tomcat process. Try moving it before the Tomcat class name so you're sure it's picked up as a command line argument for the JVM (java -Dserver.port=x tomcat.class.name)
2. There is another listener configured in Tomcat (for example, an AJP connector). Look for port 8081 in Tomcat's server.xml and either change it there or find the respective command line argument to set this to another port when starting up.