ERROR 4928 BindException Address already in use

The Spring boot application uses tomcat as a web server. The default tomcat port is 8080. If any application listens to port 8080 and if you start the spring boot application, this exception is thrown as tomcat can not use port 8080.



Exception

ERROR 4928 --- [           main] org.apache.catalina.util.LifecycleBase   : Failed to start component [Connector[HTTP/1.1-8080]]
 org.apache.catalina.LifecycleException: Protocol handler start failed
     at org.apache.catalina.connector.Connector.startInternal(Connector.java:1008) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.catalina.core.StandardService.addConnector(StandardService.java:227) [tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:263) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:195) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:297) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) [spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
     at com.yawintutor.SpringHelloWorldJspApplication.main(SpringHelloWorldJspApplication.java:10) [classes/:na]
 Caused by: java.net.BindException: Address already in use: bind
     at java.base/sun.nio.ch.Net.bind0(Native Method) ~[na:na]
     at java.base/sun.nio.ch.Net.bind(Unknown Source) ~[na:na]
     at java.base/sun.nio.ch.Net.bind(Unknown Source) ~[na:na]
     at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:na]
     at java.base/sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:na]
     at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:230) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:213) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1124) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1210) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:585) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     at org.apache.catalina.connector.Connector.startInternal(Connector.java:1005) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
     … 14 common frames omitted


Root Cause

Tomcat is running on port 8080. Spring boot application uses tomcat as the default web server. The port 8080 is currently being used by the application and tomcat is trying to listen to port 8080.



Solution 1

You’ve already started and running the spring boot application. Now you’re trying to run the spring boot application again. Stop all the instance or restart your IDE.



Solution 2

Some external applications already use port 8080. Check the running application in the task manager, stop the application that listen to port 8080

Run the command below in linux to find the application that uses port 8080, and then kill the process if you want to stop.

ps -ef | grep 8080

kill -9 <process id>


Solution 3

Change the default listening port in application.properties and start the spring boot application again

application.properties

server.port=80

How to create simple Spring Boot Application with Main method



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *