Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Web服务器无法启动。端口8080已在使用中。弹簧靴_Java_Spring Boot_Gradle - Fatal编程技术网

Java Web服务器无法启动。端口8080已在使用中。弹簧靴

Java Web服务器无法启动。端口8080已在使用中。弹簧靴,java,spring-boot,gradle,Java,Spring Boot,Gradle,我正在尝试从gradle项目调用webAPI 我的build.gradle如下所示 plugins { id 'org.springframework.boot' version '2.1.4.RELEASE' id 'java' } apply plugin: 'io.spring.dependency-management' dependencies { implementation 'org.springframework.boot:spring-boot-st

我正在尝试从gradle项目调用webAPI

我的build.gradle如下所示

plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    compile 'org.springframework.boot:spring-boot-starter-webflux'
    compile 'org.projectreactor:reactor-spring:1.0.1.RELEASE'
}
如果我删除以下依赖项

compile 'org.springframework.boot:spring-boot-starter-webflux'
它是有效的,但如果我把它加回去。它给出了如下错误:

Web server failed to start. Port 8080 was already in use.
那么,如何解决这个问题,以便使用webclient?因为应用程序不是需要端口才能运行的web应用程序。这是一种微服务


我只想使用Spring Boot的WebClient。如何在不将应用程序转换为web应用程序的情况下使用它。

您尝试使用已使用的端口

端口在传输层使用-
tcp
http
是应用层,使用传输层发送和接收请求

spring boot应用程序公开的默认端口是
8080
。在您的案例中,您有两种解决方案:

  • 更改应用程序的端口
  • 停止使用要使用的端口的服务

如果您不想启动嵌入式服务器,只需在
应用程序中设置以下属性。属性
(或
.yml
):

如果类路径包含启动web服务器所需的位,Spring Boot将自动启动它。要禁用此行为,请在application.properties中配置WebApplicationType

资料来源:



如果您的应用程序确实是一个Web应用程序,那么您可以使用
服务器.port
属性(在应用程序的
.properties
/
.yaml
文件中,作为启动时的命令行参数等)轻松更改端口。

您的客户端应用程序也可以使用spring启动应用程序,为什么有两个spring启动应用程序运行在8080端口。 更改其中一个端口或使用main类创建独立的java应用程序,将web客户端放入其中并运行。
作为http客户端,您可以使用Apache http客户端。

只需自定义您的springboot应用程序以在任何端口启动:

通过添加以下行,可以在application.properties中更改应用程序的默认端口:


server.port=8090

如果在windows上,并且您每次运行应用程序时都会收到此消息,您需要继续执行以下操作:

> netstat -ano | findstr *<port used>*

  TCP    0.0.0.0:*<port used>*  0.0.0.0:0              LISTENING       *<pid>*
  TCP    [::]:*<port used>*     [::]:0                 LISTENING       *<pid>*

> taskkill /F /PID *<pid>*
SUCCESS: The process with PID *<pid>* has been terminated.
>netstat-ano | findstr**
TCP 0.0.0.0:*0.0.0.0:0侦听**
TCP[::]:***[:]:0正在侦听**
>taskkill/F/PID**
成功:PID为**的进程已终止。
如果上面的netstat包含这样的内容

TCP    [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:540yy [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:*<port used>* TIME_WAIT 0
TCP[zzzz:e2ce:44xx:1:axx6:dxxxf:xxx:xxxx]:540yy[zzzzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:**等待时间0
然后,您可以等待一段时间,或者重新配置以使用另一个端口

我想我们可以编写一些代码,在应用程序运行时随机生成并检查端口是否空闲。虽然这将有递减的回报,因为他们开始用光。另一方面,我们可以添加一个资源清理代码,在应用程序停止后执行上面的操作

  • src/main中创建/resources文件夹
  • /resources中创建应用程序.properties文件
  • 写入
    server.port=9090
    //(使用您选择的任何端口号)

  • 今天我在SpringBoot项目中工作,我在项目中遇到了同样的错误。因此,我所做的是,单击运行最后一个工具按钮旁边的停止按钮,然后再次运行。然后,我的项目开始运行得很好。

    最好的答案是始终使用“重新启动应用程序”按钮。这将停止web服务器并在与以前相同的端口上重新启动整个应用程序

    这是一个带有红色方块和绿色播放图标的按钮


    您也可以在windows的搜索栏中编写services.msc。然后您可以找到Apache Tomcat,然后停止此Apache。我想它会工作。

    您可以在application.properties文件中设置
    server.port=#一些可用的端口号

    或者在管理员模式下运行命令提示符并运行
    netstat-a-o-n
    。 查找使用端口8080的进程id


    运行
    taskkill/F/PID#Processid
    命令

    我们很容易找到两种解决方法。 第一个是更改应用程序中的端口号

    第二,首先停止可用的正在运行的服务器,然后重新运行服务器


    我确信它可以工作:)

    如果您可以手动
    杀死端口,该端口问题可以解决

    使用
    CurrPorts
    软件,您可以查看计算机中正在运行的所有端口,如果需要,您可以关闭该端口

    您可以从下载CurrPorts。(下载链接位于页面底部)

    ================或==============

    如果没有CurrPorts,您也可以使用下面的方法来执行此操作

  • CMD as以管理员身份运行
  • 输入
    netstat-a-o-n
    并点击回车键。现在你可以看到下面这样。端口可以在
    符号后看到本地地址列
  • 选择端口正在运行的进程id
    (非端口)
    ,键入
    taskkill/F/PID
    命令,然后按enter键

  • 您可以使用npm终止端口

    **npx kill-port 8080**   //8080 for example
    
    要求:npm


    阅读更多信息:

    捕获java.net.BindException,其中包含消息:地址已在使用中,从其他可用端口开始,并将webclient与两个端口之一一起使用

    try {
                SpringApplication.run(Application.class, args);
            } catch (org.springframework.boot.web.server.PortInUseException e) {
    //Runtime.exec("pkil")..
    //or
    SpringApplication.run(Application.class, otherargs);
    //SpringApplication.run(Application.class, new String[]{"--server.port=8444"});
    //when invoked recursively it is a port rebalancer for port usage among port pool with server as from client for startup stage via application restarts within many busy ports which are used before or without querying.
    
    }
    

    如果您以前启动过spring boot应用程序,但在再次点击play之前忘记停止,请转到windows任务管理器,找到java应用程序(类似于“OpenJDK平台二进制文件”,然后单击End task(java应用程序而非eclipse)。然后再试一次运行。这对我很有效。

    你问的是同样的问题。你的8080端口已经绑定,你不能在同一个po中运行Spring boot
    **npx kill-port 8080**   //8080 for example
    
    try {
                SpringApplication.run(Application.class, args);
            } catch (org.springframework.boot.web.server.PortInUseException e) {
    //Runtime.exec("pkil")..
    //or
    SpringApplication.run(Application.class, otherargs);
    //SpringApplication.run(Application.class, new String[]{"--server.port=8444"});
    //when invoked recursively it is a port rebalancer for port usage among port pool with server as from client for startup stage via application restarts within many busy ports which are used before or without querying.
    
    }