Web server failed to start. Port 8080 was already in use. Spring Boot

If on windows and your getting this every time you run the application you need to keep doing:

> netstat -ano | findstr *<port used>*

  TCP    0.0.0.0:*<port used>*  0.0.0.0:0              LISTENING       *<pid>*
  TCP    [::]:*<port used>*     [::]:0                 LISTENING       *<pid>*

> taskkill /F /PID *<pid>*
SUCCESS: The process with PID *<pid>* has been terminated.

If netstat above includes something like this;

TCP    [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:540yy [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:*<port used>* TIME_WAIT 0

Then you can either wait for a little while or reconfigure to use another port.

I suppose we could write some code to randomly generate and check if a port is free when the application runs. Though this will have diminishing returns as they start to get used up. On the other hand could add a resource clean up code that does what we have above once the application stops.


If you don't want the embedded server to start, just set the following property in you application.properties (or .yml):

spring.main.web-application-type=none

If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it. To disable this behaviour configure the WebApplicationType in your application.properties

Source: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html


You can change the default port of your application in application.properties by adding the following line:

server.port = 8090