8080 port already taken issue when trying to redep

2020-02-07 16:05发布

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.

18条回答
Summer. ? 凉城
2楼-- · 2020-02-07 16:14

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)
查看更多
ら.Afraid
3楼-- · 2020-02-07 16:15

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.

sudo lsof -i tcp:8080

kill -15 PID

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

The first command will give 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.

查看更多
霸刀☆藐视天下
4楼-- · 2020-02-07 16:16

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

查看更多
男人必须洒脱
5楼-- · 2020-02-07 16:17

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.

  2. Now try to reLaunch or stop your application.

Go to Task Manager and end Java(tm) platform se binary click here to view image https://www.google.com/search?q=what+is+java(tm)+platform+se+binary&oq=what+is+java(tm)+platform+se+binary&aqs=chrome..69i57.26349j1j7&sourceid=chrome&ie=UTF-8

  1. Go to application.properties file set server.port=0. This will cause Spring Boot to use a random free port every time it starts.
查看更多
仙女界的扛把子
6楼-- · 2020-02-07 16:19

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

查看更多
▲ chillily
7楼-- · 2020-02-07 16:20

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.

查看更多
登录 后发表回答