5

I am trying to run a spring boot application by clicking on Run as -> Spring Boot App. I am getting the error as :

Caused by: java.net.BindException: Address already in use: bind

When I use netstat command, I see the below without process Ids:

netstat -na | find "8080"

TCP    0.0.0.0:8080   0.0.0.0:0    LISTENING

TCP    [::]:8080      [::]:0       LISTENING

Notice - I am running my code on windows machine

How do I kill these processes?

dWinder
  • 11,597
  • 3
  • 24
  • 39
user10411549
  • 53
  • 1
  • 1
  • 5
  • On windows machine add the `o` flag to get the process ID (as `netstat -nao | find "8080"`) and then you can kill it with `Taskkill` – dWinder Sep 25 '18 at 06:57

4 Answers4

9

You can change your application's port number by providing something like server.port=4567 in your application.properties.

OR

You can follow the steps as mentioned in http://www.codeman.in/blog/windows-kill-process-by-port-number-157 to kill process running on a port number:-

enter image description here

Kartik
  • 7,677
  • 4
  • 28
  • 50
1

Try the command lsof -i, it should list network connections among pid. Or even better lsof -i :8080

gtosto
  • 1,381
  • 1
  • 14
  • 18
  • 1
    Hello, I forgot to mention I am running this code on my Windows machine. So, I am unable to run the above command lsof -i – user10411549 Sep 25 '18 at 06:55
0

most likely "8080" is being used, either you end task/close the application or simply change the by default port which is being used by Spring boot. Multiple ways you can achieve, application.properties is one of them.

Niraj Jha
  • 455
  • 3
  • 10
0
try {
            SpringApplication.run(Application.class, args);
        } catch     (org.springframework.boot.web.server.PortInUseException e) {
//Runtime.exec("pkil")..
//or
SpringApplication.run(Application.class, otherargs);
//SpringApplication.run(Application.class, new String[]{"--server.port=8444"});
//when invoked recursively it is a port rebalancer for port usage among port pool with server as from client for startup stage via application restarts within many busy ports which are used before or without querying.

}
Oleksii Kyslytsyn
  • 2,458
  • 2
  • 27
  • 43