英文:
Web server failed to start. Port 8080 was already in use
问题
我正在尝试使用Spring Boot在STS中开发一个Web应用程序。在运行我的应用程序时,我遇到了以下错误:
描述:
> Web服务器启动失败。端口8080已被占用。
操作:
> 识别并停止监听端口8080的进程,或者
> 配置此应用程序以侦听另一个端口。
我尝试关闭了占用端口8080的应用程序。我找到了占用端口的PID,并使用以下命令终止了它:
taskkill /F /PID pidname
我重新启动了STS并尝试再次运行,但仍然出现相同的错误。
英文:
I am trying to develope a webapp using spring boot in STS. While running my app i am getting
Description:
> Web server failed to start. Port 8080 was already in use.
Action:
> Identify and stop the process that's listening on port 8080 or
> configure this application to listen on another port.
I have tried to close the application for port 8080. I found the PID for the port and terminated it using
taskkill /F /PID pidname
I restarted the STS and tried to run again but its throwing the same error.
答案1
得分: 2
如果端口被某个操作系统线程占用,要停止它可能有点棘手。虽然这并不总是一个很好的解决方案,但如果您仍然希望在开发环境中继续开发而不会遇到任何问题,您可以使用这个替代方案。
这里还有另一种方法可以使用。您可以将Spring Boot服务器的默认端口替换为其他端口号。
对于服务器端口,属性是 server.port
。
如果您正在使用 application.properties
文件:
server.port=8081
它将在端口8081上启动服务器。
同样,如果使用 application.yml
文件,也可以执行相同的操作:
server:
port : 8081
每个文件都会在Maven应用程序的 src/main/resources
目录中放置时由Spring Boot加载。
英文:
If port is acquired by some OS thread, it would be a bit tricky to stop it. Although it's not always great solution, but if you still want to continue with your development without any issue you can use this alternative solution (as you are in development environment).
Here is another thing you can use. You can replace the default port for Spring Boot server to some other port number.
For server port the property is server.port
.
If you are using application.properties
file:
server.port=8081
It will start server on port 8081.
Similarly, you can do the same if using an application.yml
file:
server:
port : 8081
Each file is loaded by Spring Boot if placed in the src/main/resources
directory of a Maven application.
答案2
得分: 0
您唯一的其他选择(除了使端口8080可用或在Spring Boot中使用另一个端口)是在Docker中运行应用程序:
在应用程序目录中创建一个Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
在终端中运行
sudo docker build -t spring-app . && docker run -d -p 8080:8080 -t springapp
(假设您已安装Docker,请安装它如果您尚未安装)
英文:
Your only other option (beside making port 8080 available or using another port for spring boot) is running the application in docker:
Create a Dockerfile in your application directory
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Run in terminal
sudo docker build -t spring-app . && docker run -d -p 8080:8080 -t springapp
(This assumes you have docker installed, please install it if you don’t have it)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论