5

I have a problem with running my sample Spring Boot Application. When I try to run it, this error occurs:

 java.net.BindException: Address already in use: bind
            at sun.nio.ch.Net.bind0(Native Method)
            at sun.nio.ch.Net.bind(Unknown Source)
            at sun.nio.ch.Net.bind(Unknown Source)
            at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
            at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
            at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473)
o.apache.catalina.core.StandardService   : Failed to initialize connector [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]

    org.apache.catalina.LifecycleException: Failed to initialize component [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]]
            at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
            at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
            at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
            at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
            at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
            at org.apache.catalina.startup.Tomcat.start(Tomcat.java:335)
            at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:57)
            at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:52)
            at 
Rozart
  • 1,540
  • 11
  • 24
reza ramezani matin
  • 1,041
  • 2
  • 13
  • 33
  • please more info. Do you use maven? can you the applications.properties file and other files, pom.xml, main class, .... – emoleumassi Jan 15 '16 at 10:11

10 Answers10

7

"Address already in use" means, there is already another application running on port 8080. Use your OS tools to find that process and end it, before you start your application, or let your application run on another port. If you use an embedded server in your Boot application, you can specify the following property:

server.port=8085 

Of course you can choose whatever port you want.

dunni
  • 38,210
  • 8
  • 94
  • 96
  • Almost "whatever port" depending on your needs and setup, in respect to the [1024 privileged ports](https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html). – Morfic Jan 15 '16 at 09:58
7

In the first time you run ok right? and run again it got an error? If right, You need stop service before run again. Here is way to stop. Click to button stop look like this image

enter image description here

Bacteria
  • 7,810
  • 10
  • 47
  • 61
Sang9xpro
  • 193
  • 2
  • 4
2

I have a very simple solution:

As the answer above stated, when you start Spring Boot app, the PID of underneath server(Tomcat or Undertow, or whatever) will be shown in the console; you may start again the app without terminating the former one, especially when you are in debug mode, thus the error. This applies to Intellij, too.

But, if you have started again, the PID is no longer available for you because previous session output is cleared.

So, if you are using Eclipse, just close it, and open Task Manager to terminate other java.exe JVM process. Be sure that you have no other JVM-based services running which cannot be stopped. (Like Kafka server, Apache Storm, etc.)

The Tomcat instance is one of them.

WesternGun
  • 7,222
  • 56
  • 97
  • killing the java process is great just in case there are rogue process holding up the port after shutting down the app. Thanks for sharing the trick. – Doogle Feb 06 '19 at 11:52
1

Log shows that server is already started on port 8080. I faced the same problem. go to windows task manager and end process that is javaw.exe, it worked on my application.

nurdan karaman
  • 173
  • 2
  • 2
  • 11
0

Two possibilities

P1.Another Application is using port 8080

Solution:-

  • a.Stop that application and free port 8080 for your application.
  • b.Change your application server port, for that create a file named application.properties in resource folder and add property

    server.port = 8085

(8085 can be replaced by any port number of your choice which will not conflict with other application server ports)

  1. location of application.properties file
  2. snippet of application.properties file

P2. Your application is already running

Solution

  • a. Pretty simple solution for this situation is stop your currently running application and rerun it
  • b.If you want to run multiple instances of your application then keep current application running change server port as explained above and run the application the new instance will run of another port.
SwapnilKumbhar
  • 240
  • 1
  • 4
  • 14
0

Even I faced this issue u can just stop the application(there is a stop button on the top toolbar) and restart again it worked for me and I used STS

Pradeep
  • 1
  • 1
0

In the Eclipse situation, check if there are items running in the window "Progress"(Windows > Show View > Progress) Stop the running process, which might be locking your desired port.

RAY
  • 1,941
  • 2
  • 16
  • 15
0

Got the same error. The springboot application has inbuilt tomcat server which runs on port 8080..if you have any other process currently running on port 8080,The java.net.BindException will raise..so kill the processes which are using 8080 thorugh cmd as follows:

-->

 open command prompt as Administrator.
--> netstat -ano | findstr :<PORT>
       netstat -ano | findstr :8080
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       10568
  TCP    [::]:8080              [::]:0                 LISTENING       10568
-->taskkill /PID <PID> /F
   taskkill /PID 10568 /F

Now if you want recheck your running process by using netstat -ano | findstr :8080 command.. and again restart or rerun our application.. This is for first ever time you wanted to run springboot application. Hope this might be helpfull,worked for me :)

Second case:

In the first time you run ok right? and run again it got an error? If right, You need stop service before run again..if it is the case follow @Sang9xpro answer above.

TechiePro
  • 21
  • 4
-1

Seems your server is already up. If you are using linux based system, type following command in terminal to check which port is active on your system.

"ps -ef | grep 8080"(or whatever port is mentioned)

Now you need to kill this one if you wish to run the server on same port.

kill -9 8080

Voilla!! Try booting your application once again and it will work.

Extra: You'll come to me complaining an important application is already listening on mentioned port(8080) and you do not want to kill it. No probs.

Create an application.properties file inside your resource folder and change port to whatever you like.

server.port = 8081

Voilla!! You did it!! :) Let me know if further clarifications required.

Pratik Ambani
  • 1,993
  • 1
  • 14
  • 23
  • `kill -9 8080` performs forced kill of a process identified by PID 8080, not a process that binds to this port. This advice is destructive. – Mikhail Antonov Oct 05 '18 at 08:43
-2

This is because you have run the spring boot application once in your eclipse IDE and closed the application and you assume that the embedded server is stopped. But it is not the case. Even after you closed your application in Eclipse -> Console window, embedded tomcat server is running. What you can do is, run your spring boot application again and look at the console messages. Immediately after Spring Logo, you can find Starting on with PID 16676. This is the PID you need to search in "Wndows Task Manager -> Processes -> PID". Select that process and "End Task". Now if you start your spring boot application, it will start without issues.

  • You can improve your answer by formatting it better. Take a look at the formatting guide for details: https://stackoverflow.com/help/formatting – Faheel Jun 14 '18 at 17:56
  • Sorry, but what I see is "Starting MyApplication on localhost with PID 7540", it is to say that your new instance is started with PID 7540, not the former one. – WesternGun Jul 16 '18 at 14:59
  • But, it is true that the PID of each Tomcat server will be displayed in console, so if you record them and terminate them in task manager, you can solve this error. – WesternGun Jul 17 '18 at 07:25