[英]Port already in use 8080 error prompts in Eclipse but it does work on port 8080 in web browser when running
Used to run Spring MVC project is Eclipse Version: 2020-03 (4.15.0) using Tomcat 8.5.用于运行 Spring MVC 项目是 Eclipse 版本:2020-03 (4.15.0) 使用 Tomcat 8.5。 When I run the project it displays "port already in use error" in console, but when I run on browser localhost:8080/ it works.
当我运行该项目时,它会在控制台中显示“端口已在使用中的错误”,但是当我在浏览器 localhost:8080/ 上运行时它可以工作。 But when I look in to the 'Servers' section in Eclipse it stopped but I think it is managed by Spring boot configuration that I included in pom.xml.
但是当我查看 Eclipse 中的“服务器”部分时,它停止了,但我认为它是由我包含在 pom.Z0F635D0E0F3874FFF8B581C132E6CC7A 中的 Spring 引导配置管理的。 and there the server is started already in port 8080, correct me if I am wrong there.
并且服务器已经在端口 8080 中启动,如果我错了,请纠正我。
I am confused what exactly 'Server' section shows in Eclipse project and how we can change the port to something else from Eclipse, if possible?我很困惑 Eclipse 项目中的“服务器”部分到底显示了什么,如果可能的话,我们如何将端口从 Eclipse 更改为其他端口?
could someone help me to understand this by explaining what actually happening in the background?有人可以通过解释后台实际发生的事情来帮助我理解这一点吗? bs: there's new server folder created out of the workspace when I add new server.
bs:当我添加新服务器时,在工作区之外创建了新的服务器文件夹。
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Follow the following steps:请按照以下步骤操作:
-Dserver.port=8081
-Dserver.port=8081
Instead of 8081
you can put any other port number also.除了
8081
,您还可以输入任何其他端口号。
Manually going to localhost:8080 works because of the error message.由于错误消息,手动转到 localhost:8080 有效。 Another process, likely another copy of Tomcat, is already running and listening on that port--it's what is sending a response back to your browser.
另一个进程,可能是 Tomcat 的另一个副本,已经在该端口上运行并监听——它正在向浏览器发送响应。 The right side of the server editor you're showing in the first image has the Ports section visible.
您在第一张图片中显示的服务器编辑器的右侧有可见的端口部分。 That is where you can change the Port numbers for the instance you launch from Eclipse.
您可以在此处更改从 Eclipse 启动的实例的端口号。
There is a hanging java process that listens on that port.有一个挂起的 java 进程正在侦听该端口。
Find the process by port and kill it.通过端口找到进程并杀死它。
for linux you can use fuser -k 8080/tcp
对于 linux 你可以使用
fuser -k 8080/tcp
for windows netstat -ano | findstr:PORT_NUMBER
对于 windows
netstat -ano | findstr:PORT_NUMBER
netstat -ano | findstr:PORT_NUMBER
to get the PID and then kill it netstat -ano | findstr:PORT_NUMBER
获取 PID 然后将其杀死
apart from that you can use JavaVisualVM
to track all java applications running on your machine除此之外,您可以使用
JavaVisualVM
跟踪您机器上运行的所有 java 应用程序
I would happy ifsomeone vote up this question, I feel it's a valid question as there are some confusion might raise as many configurations options available like embedded server vs stand alone server, spring boot behaviour when it comes to loading the relevant dependencies to class path.如果有人对这个问题投赞成票,我会很高兴,我觉得这是一个有效的问题,因为在将相关依赖项加载到 class 路径时,可能会出现许多可用的配置选项,例如嵌入式服务器与独立服务器、spring 引导行为。
happy if someone vote this question up, so I keep continue my profile updated.如果有人投票支持这个问题,我会很高兴,所以我会继续更新我的个人资料。
thanks.谢谢。
Alright, I found the answer after spending time on research and trail & error.Thanks for everyone who contributed to this question, that's what it makes me to spend more time to understand the problem.好吧,我在花时间研究和跟踪错误后找到了答案。感谢所有为这个问题做出贡献的人,这就是让我花更多时间来理解问题的原因。 Since actually I am a beginner on work on creating spring project from scratch.
因为实际上我是从头开始创建 spring 项目的初学者。 Please bear with me.
请多多包涵。
Actually I would like to point out these.其实我想指出这些。
1) This project is initialized from https://start.spring.io/ , so that means it is spring boot based project, not a plain spring-MVC project(with those.XML files). 1) This project is initialized from https://start.spring.io/ , so that means it is spring boot based project, not a plain spring-MVC project(with those.XML files).
2) I have been running it on an embedded Tomcat server where I should follow the practice when I run the application. 2) 我一直在嵌入式 Tomcat 服务器上运行它,我在运行应用程序时应该遵循该实践。 one approach is
./mvnw spring-boot:run
and another approach is creating a .JAR
file by ./mvnw clean package
and run it.一种方法是
./mvnw spring-boot:run
,另一种方法是通过./mvnw clean package
创建一个.JAR
文件并运行它。
I did the mistake by attaching the another Tomcat(stand-alone) server when I run the application via Eclipse.当我通过 Eclipse 运行应用程序时,我通过附加另一个 Tomcat(独立)服务器犯了错误。 So that is wrong.
所以这是错误的。
Here you can see now there is no server displays under 'Server' section in Eclipse but when I run the application it runs successfully (see the console) and listening to default port 8080 also if I want to change the port that is possible by passing as a argument.在这里您现在可以看到 Eclipse 的“服务器”部分下没有服务器显示,但是当我运行应用程序时,它会成功运行(参见控制台)并且如果我想通过传递更改可能的端口,也可以监听默认端口 8080作为论据。
-Dserver.port=8081
or every other options you guys suggested. -Dserver.port=8081
或你们建议的所有其他选项。
any suggestions for improving this highly appreciated.任何改进这个高度赞赏的建议。 please vote if you feel good about my findings.
如果您对我的发现感觉良好,请投票。
references:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.