Ano*_*tor 21 java gradle spring-boot
我正在尝试从 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'
}
Run Code Online (Sandbox Code Playgroud)
如果我删除以下依赖项
compile 'org.springframework.boot:spring-boot-starter-webflux'
Run Code Online (Sandbox Code Playgroud)
它有效,但如果我将其添加回来。它给出了错误
Web server failed to start. Port 8080 was already in use.
Run Code Online (Sandbox Code Playgroud)
那么,我该如何解决这个问题,以便我可以使用 webclient?因为应用程序不是需要端口才能运行的 Web 应用程序。它是一种微服务。
我只想使用 Spring Boot 的 WebClient。如何在不将我的应用程序转换为 Web 应用程序的情况下使用它。
crw*_*ils 41
另一种方法是首先检查哪些进程正在使用该特定端口,然后使用其进程 ID 终止它:
运行lsof -i :8080
这将识别哪个进程正在侦听端口 8080。
记下进程 ID (PID),例如 63262
运行kill -9 <PID>例如kill -9 63262
Sup*_*wan 30
有时如果您可以手动kill the that port解决问题。
使用CurrPorts软件,您可以查看计算机中正在运行的所有端口,如果需要,您可以终止该端口。
您可以从这里下载 CurrPorts 。(下载链接在页面底部)
============== 或 ==============
如果没有 CurrPorts,您也可以使用如下方法来执行此操作。
netstat -a -o -n并按回车键。现在你可以看到如下所示。端口标志后可以看到本地地址栏:。(not port)选择您的端口运行的进程 ID ,然后键入taskkill /F /PID <process_id_here>命令并按 Enter 键。Ala*_*yle 27
如果在 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.
Run Code Online (Sandbox Code Playgroud)
如果上面的 netstat 包含这样的内容;
TCP [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:540yy [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:*<port used>* TIME_WAIT 0
Run Code Online (Sandbox Code Playgroud)
然后您可以稍等片刻或重新配置以使用另一个端口。
我想我们可以编写一些代码来随机生成并检查应用程序运行时端口是否空闲。尽管随着它们开始用完,这将带来收益递减。另一方面,可以添加一个资源清理代码,一旦应用程序停止,它就会执行我们上面的操作。
Gus*_*ini 19
如果您不想启动嵌入式服务器,只需在您application.properties(或.yml)中设置以下属性:
spring.main.web-application-type=none
Run Code Online (Sandbox Code Playgroud)
如果您的类路径包含启动 Web 服务器所需的位,Spring Boot 将自动启动它。要禁用此行为,请在 application.properties 中配置 WebApplicationType
来源:https : //docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html
如果您的应用程序确实是一个 Web 应用程序,那么您可以使用该server.port属性轻松更改端口(在您的应用程序的.properties/.yaml文件中,作为启动时的命令行参数等)。
小智 9
server.port=9090 //(使用您选择的任何端口号)小智 7
您可以使用 npm 杀死端口
**npx kill-port 8080** //8080 for example
Run Code Online (Sandbox Code Playgroud)
要求:npm
阅读更多:https : //www.npmjs.com/package/kill-port
小智 6
如果端口:8080已在使用中发生错误:
以管理员身份打开命令提示符
步骤1:netstat -ano | findstr :<输入您的 4 位端口号>
netstat -ano | findstr :8080
Run Code Online (Sandbox Code Playgroud)
TCP 0.0.0.0:8080 0.0.0.0:0 监听 6436
TCP [::]:8080 [::]:0 监听 6436
步骤2:taskkill /PID <输入上面的pid号(有时显示3/4/5/6位)> /F
taskkill /PID 6436 /F
Run Code Online (Sandbox Code Playgroud)
成功:PID 6436 的进程已终止。
| 归档时间: |
|
| 查看次数: |
116764 次 |
| 最近记录: |