I'm developing a REST API using Spring Framework.
First I wasn't able to run my application because of the same problem. The port 8080 on my computer is busy.
Then I found out that one alternative to solve this problem is creating an application.properties
file under src/main/resources
folder.
That's what I made, and set up the server to listen on port 8090. This worked but only for the first time, now I'm getting the same exception whenever I try to run the application for the second time.
Description:
The Tomcat connector configured to listen on port 8090 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 8090, or configure this application to listen on another port.
As far as I know, this framework makes use of an embedded instance of apache tomcat to deploy every application.
My guess is, the server is not getting restarted the second time I try to run the app, that's why the output says " The port may already be in use or the connector may be misconfigured"
So, a more specific question would be, how can I manage the embedded instance of apache tomcat either manually or programmatically?
I've also modified the port in the application.properties
file twice. It works fine, but again, only for the first time. As you can imagine I cannot do the same each time the app is going to be executed.
This question is related to
java
spring
eclipse
tomcat
spring-boot
There are two options to handle/avoid this situation.
Open the console --> right click --> terminate all.
Find the process and terminate it. On Windows do a Control+Alt+Delete and then find the "Java(TM) Platform SE Binary" process under the Processes Tab. For example:
On Ubuntu, you can use "ps aux | grep java" to find the process and "kill -9 PID_NUMBER" to kill the process.
OR
If you're using a Spring boot application, go to application.properties and add this:
server.port = 8081
If you have devtools like auto build dependency remove it. It is automatically build your project and run it. When you build manually it show port in use.
Another easy way of solving this error is right clicking in the console and click on Terminate/Disconnect All. Afterwards run the application it should work fine.
if it's convenient for you, and you don't want to use the command line, you can reboot your computer, it helps!
In your windows os follow the following steps:
Issue: It's because either you are not stopping your application or the application is already somehow running on the same port somehow.
Solution, Before starting it another time, the earlier application needs to be killed and the port needs to be freed up.
Depending on your platform you can run the below commands to stop the application,
on windows
netstat -anp | find "your application port number"` --> find PID
taskkill /F /PID
on Linux,
netstat -ntpl | grep "your application port number"
kill pid // pid you will get from previous command
on Mac OS
lsof -n -iTCP:"port number"
kill pid //pid you will get from previous command
The easier way to solve this is changing the port on the application.properties file;
server.port=8081
this issue can be resolved using 2 ways:
netstat -ao | find "8080" Taskkill /PID 1342 /F
server.port=8081
In case your app is run on httpS, make sure you put right values under the following properties:
server.ssl.key-store-password=
server.ssl.key-alias=
I got the same error when I put the wrong values here
Find the process ID (PID) for the port (e.g.: 8080)
On Windows:
netstat -ao | find "8080"
Other Platforms other than windows :
lsof -i:8080
Kill the process ID you found (e.g.: 20712)
On Windows:
Taskkill /PID 20712 /F
Other Platforms other than windows :
kill -9 20712 or kill 20712
For those who are experiencing same problem after controlling there is no suspicious java process which allocate the port, there is no red square on eclipse to terminate any process and also there is no change even you try different port for your spring boot application.
might sound stupid but; restarting eclipse works. :)
We have had the same issue in eclipse or intellij. After trying many alternative solutions, I found simple solution - add this config to your application.properties:
spring.main.web-application-type=none
On Windows:
To get started, open the command prompt by clicking on Start and then typing cmd. In the command window, go ahead and type in the following command:
netstat -a -n -o
In the command above, the -o parameter is what will add the PID to the end of the table. Press enter and you should see something like this:
Now to see the name of the process that is using that port, go to Task Manager by pressing CTRL + SHIFT + ESC and then click on the Process tab. In Windows 10, you should click on the Details tab.
By default, the task manager does not display the process ID, so you have to click on View and then Select Columns.
You might also need to look into services running in background. To do that right-click and select open services as shown below:
Hope it helps :)
Source: Stackoverflow.com