[java] 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE

I have strange thing when I try to modify Spring project inside my Spring Tool Suite. On the first load (deploy) everything is fine, application compiles and runs on localhost:8080

When I change something inside code and try to redeploy it (Run it again - Run As Spring Boot App) I get error message

*************************** APPLICATION FAILED TO START


Description:

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

2016-10-19 00:01:22.615 INFO 10988 --- [ main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3023df74: startup date [Wed Oct 19 00:01:19 CEST 2016]; root of context hierarchy 2016-10-19 00:01:22.616 INFO 10988 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

If I shutdown process on that port manually everything works fine again, but this can't be right way of redeploying Spring app. Am I doing something wrong here?

I'm using :: Spring Boot :: (v1.4.1.RELEASE)

P.S. I'm aware that I can setup some kind of hot-swap mechanism to have automatic reload of page after I change code, but for now I would like to resolve this issue first.

Thanks for any kind of help or info.

This question is related to java spring spring-mvc tomcat spring-boot

The answer is


You have to stop the current process and run your new one. In Eclipse, you can press this button to ReLaunch your application: enter image description here


Just click red button to stop all services on eclipse than re- run application as Spring Boot Application - This worked for me.


Print the list of running processes and try to find the one that says spring in it. Once you find the appropriate process ID (PID), stop the given process.

ps aux | grep spring
kill -9 INSERT_PID_HERE

After that, try and run the application again. If you killed the correct process your port should be freed up and you can start the server again.


If you are using linux system, use the below command.

fuser -k some_port_number/tcp - that will kill that process.

Sample:-

fuser -k 8080/tcp

Second Option: Configure the tomcat to use a new port


It sometimes happen even when we stop running processes in IDE with help of Red button , we continue to get same error.

It was resolved with following steps,

  1. Check what processes are running at available ports

    netstat -ao |find /i "listening"

    We get following

    TCP 0.0.0.0:7981 machinename:0 LISTENING 2428 TCP 0.0.0.0:7982 machinename:0 LISTENING 2428 TCP 0.0.0.0:8080 machinename:0 LISTENING 12704 TCP 0.0.0.0:8500 machinename:0 LISTENING 2428

    i.e. Port Numbers and what Process Id they are listening to

  2. Stop process running at your port number(In this case it is 8080 & Process Id is 12704)

    Taskkill /F /IM 12704 (Note: Mention correct Process Id)

For more information follow these links Link1 and Link2.

My Issue was resolved with this, Hope this helps !


There are two ways to resolve this issue.Try option 1 first, if it doesn't work try option 2, and your problem is solved.

1) On the top right corner of your console, there is a red button, to stop the spring boot application which is already running on this port just click on the red button to terminate.

2) If the red button is not activated you need to right click on the console and select terminate/disconnect all. Hope this helps.

Bonus tip:- If you want to run your server on a different port of your choice, create a file named application.properties in resource folder of your maven project and write server.port=3000 to run your application on port 3000


Open "localhost:8080" on your browser and see what is running on this port. I did it and I just found Oracle 10g XE running on background, so I went to start->Services and stopped all oracle services. Then I redo mvnw spring-boot:run on IntelliJ and it runs like magic.


The reason is one servlet container is already running on port 8080 and you are trying to run another one on port 8080.

    1. Check what processes are running at available ports.

      • For Windows :

      • netstat -ao |find /i "listening" Image01

      OR

      • netstat -ano | find "8080" (Note: 8080 is port fail to start) Image02
    1. Now try to reLaunch or stop your application.

      • To relaunch: you can press this button

    Image03

    • To stop in windows:

    Taskkill /F /IM 6592 Note: Mention correct Process Id

    Image04

    right click on the console and select terminate/disconnect all

    • Go to Task Manager and end Java(tm) platform se binary

    click here to view image

    What is java(tm) platform se binary(Search in google

Another option is :

Go to application.properties file set server.port=0. This will cause Spring Boot to use a random free port every time it starts.


In my case, the error occurred as the application was unable to access the keystore for ssl.

Starting the application as root user fixed the issue.


Am I doing something wrong here?

Yes, you are. One servlet container is already running on port 8080 and you are trying to run another one on port 8080 again.

Either restart the server (If there is button for that in STS) or stop and start it


Create application.properties file under src/main/resources folder and write content as

server.port=8084

Its runs fine. But every time before run need to stop application first by click on red button upper on the IDE enter image description here

or try

RightClick on console>click terminate/Disconnect All


On Linux Machine, save the bash script and execute it. If you want to free port 8080, Input 8080 when prompted

echo "Enter port number to be closed :: "
read port
sudo kill $(sudo lsof -t -i:$port)

You can use list open file command and then kill the process like below.

sudo lsof -t -i tcp:8181 | xargs kill -9

or

sudo lsof -i tcp:8181

kill -9 PID

For Mac users(OS X El Capitan):

You need to kill the port that localhost:8080 is running on.
To do this, you need to do two commands in the terminal :N

sudo lsof -i tcp:8080

kill -15 PID 

NB! PID IS A NUMBER PROVIDED BY THE FIRST COMMAND.

The first command gives you the PID for the localhost:8080.
Replace the PID in the second command with the PID that the first command gives you to kill the process running on localhost:8080.


No Need to manually start an application every time at time of development to implements changes use 'spring-boot-devtool' maven dependency.

Automatic Restart : To use the module you simply need to add it as a dependency in your Maven POM:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>

When you have the spring-boot-devtools module included, any classpath file changes will automatically trigger an application restart. We do some tricks to try and keep restarts fast, so for many microservice style applications this technique might be good enough.


If you got any error on your console by saying, “Embedded servlet container failed to start. Port 8080 was already in use.” Then go to application.properties file and add this property “server.port = 8090”.

Actually the default port for spring boot is 8080, if you have something else on that port, the above error will occur. So we are asking spring boot to run on other port by adding “server.port = 8090” in application.properties file.


hi creating a simple line in application.properties as SERVER_PORT=8090 solved the issue.


This is a typical startup failure due to the embedded servlet container’s port being in use.

Your embedded tomcat container failed to start because Port 8080 was already in use.

Just Identify and stop the process that's listening on port 8080 or configure (in you application.properties file )this application to listen on another port.


One simple solution for me that worked was to : - Restart the IDE, since the stop Button was no longer visible.


There are some processes left in the background on that port, several reasons can cause this problem, but you can solve easily if you end process which is related to 8080 or Spring.

If you are using Linux there is steps how to end process:

  1. Open terminal and type command "htop"
  2. press key F3(it will allow you to search)
  3. Type "8080" if there was no result on 8080 after that try "spring"
  4. Then Press F9(KILL) And press "9"(SIGKILL)

this will kill process which is left on 8080 port and let you run application.


Goto Window->Preferences, search for Launching.

Select the "Terminate and Relaunch while launching" option.

Press Apply.


In Spring Boot Application (Using Spring Starter Project) We Have Update Port in Server.xml using Tomcat server and Add this port in application.property( insrc/main/resources) the code is server.port=8085

And update Maven Project then run application


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to spring

Are all Spring Framework Java Configuration injection examples buggy? Two Page Login with Spring Security 3.2.x Access blocked by CORS policy: Response to preflight request doesn't pass access control check Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified Spring Data JPA findOne() change to Optional how to use this? After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName The type WebMvcConfigurerAdapter is deprecated No converter found capable of converting from type to type

Examples related to spring-mvc

Two Page Login with Spring Security 3.2.x ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Spring 5.0.3 RequestRejectedException: The request was rejected because the URL was not normalized The type WebMvcConfigurerAdapter is deprecated RestClientException: Could not extract response. no suitable HttpMessageConverter found Spring boot: Unable to start embedded Tomcat servlet container UnsatisfiedDependencyException: Error creating bean with name 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

Examples related to tomcat

Jersey stopped working with InjectionManagerFactory not found The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat Spring boot: Unable to start embedded Tomcat servlet container Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists Spring Boot application in eclipse, the Tomcat connector configured to listen on port XXXX failed to start Kill tomcat service running on any port, Windows Tomcat 8 is not able to handle get request with '|' in query parameters? 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE 403 Access Denied on Tomcat 8 Manager App without prompting for user/password Difference between Xms and Xmx and XX:MaxPermSize

Examples related to spring-boot

Access blocked by CORS policy: Response to preflight request doesn't pass access control check Why am I getting Unknown error in line 1 of pom.xml? Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured How to resolve Unable to load authentication plugin 'caching_sha2_password' issue ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName ERROR Source option 1.5 is no longer supported. Use 1.6 or later How to start up spring-boot application via command line? JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value