简体   繁体   English

Eclipse 中的端口已在使用 8080 错误提示,但它在运行时在 web 浏览器中的端口 8080 上工作

[英]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:当我添加新服务器时,在工作区之外创建了新的服务器文件夹。 端口已在使用错误,配置设置为 8080 服务器已停止,.properties 文件中未添加端口 但它适用于端口 8080

<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:请按照以下步骤操作:

  1. Go to run configuration Go 运行配置
  2. Create new run configuration创建新的运行配置
  3. Go to arguments tab Go 到 arguments 选项卡
  4. Go to vmArguments Go 到 vmArguments
  5. there enter: -Dserver.port=8081输入: -Dserver.port=8081
  6. Click on apply and close.单击应用并关闭。

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或你们建议的所有其他选项。 没有任何独立服务器 但应用程序运行在嵌入式服务器之上 默认端口:8080

any suggestions for improving this highly appreciated.任何改进这个高度赞赏的建议。 please vote if you feel good about my findings.如果您对我的发现感觉良好,请投票。

references:参考:

  1. what-is-spring-boot什么是弹簧启动
  2. serving-web-content服务网络内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tomcat 服务器错误 - 端口 8080 已在使用中 - Tomcat Server Error - Port 8080 already in use Web 服务器启动失败。 8080 端口已被使用 - Web server failed to start. Port 8080 was already in use 端口 8080 已在使用中,并且没有列出使用 8080 的进程 - port 8080 is already in use and no process using 8080 has been listed 部署错误:Tomcat启动失败,服务器8080端口已被占用 - Deployment error:Starting of Tomcat failed, the server port 8080 is already in use 添加 test/resources/application.properties 后,运行 SpringBootTest 不断引发错误“端口 8080 已在使用中” - Running SpringBootTest keeps raising error "Port 8080 already in use" after adding test/resources/application.properties 为什么 Tomcat 可以使用端口 8080 而不是 80? - Why does Tomcat work with port 8080 but not 80? JVM_Bind 端口 8080 已在使用中 -- 但该端口上没有进程 - JVM_Bind port 8080 already in use -- but there are no processes on that port 在码头上运行servlet时收到错误消息“服务器端口正在使用8080-Http” - Getting error message “Server port In Use 8080-Http” when running servlet on jetty 启动 spring 启动应用程序给出错误:org.springframework.boot.web.server.PortInUseException:端口 8080 已在使用中 - Launching spring boot application gives error : org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use Web 服务器启动失败。 端口 8080 已被使用。 Spring 启动微服务 - Web server failed to start. Port 8080 was already in use. Spring Boot microservice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM