Home > database >  Tomcat address already in use error due to two applications running on local machine
Tomcat address already in use error due to two applications running on local machine

Time:02-16

I'm getting this error in my Java application:

ERROR o.a.catalina.core.StandardService – Failed to start connector [Connector[HTTP/1.1-9004]] org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-9004]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:265) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:208) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) at ie.aviva.app.TomcatApp.main(TomcatApp.java:31) Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed at org.apache.catalina.connector.Connector.startInternal(Connector.java:1020) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 13 common frames omitted Caused by: java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:461) at sun.nio.ch.Net.bind(Net.java:453) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:222) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:85) at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ... 14 common frames omitted

I'm guessing two of my applications are trying to start Tomcat on the same port but I've no knowledge or experience of tomcat. Also assume it's embedded in SpringBoot in some way. How do I investigate/resolve this?

CodePudding user response:

You can set the server port in application.properties

server.port=8081

or application.yml:

server:
  port: 8081

One of both files is probably present in src/main/resources, if not, you can create one.

CodePudding user response:

I am assuming your machine is already having 8080 port running which you probably don't want. So to kill that connection follow these two simple steps (in case you want to use 8080 for your application):

Get the PID for 8080 port by typing this on your terminal: netstat -n -a -o | grep '8080'

Kill the process to free 8080 port: taskkill /F /PID 1234 (suppose the PID is 1234)

  • Related