我正在尝试从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应用程序的情况下使用它。
如果在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包含这样的内容;
TCP [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:540yy [zzzz:e2ce:44xx:1:axx6:dxxf:xxx:xxxx]:*<port used>* TIME_WAIT 0
然后,您可以等待一段时间或重新配置以使用另一个端口。
我想我们可以编写一些代码来随机生成并检查应用程序运行时端口是否空闲。尽管当它们开始耗尽时,这将具有递减的回报。另一方面,可以添加一个资源清理代码,在应用程序停止后执行我们上面的操作。
您可以通过添加以下行在application.properties中更改应用程序的默认端口:
服务器端口
如果您不希望嵌入式服务器启动,只需在application.properties
(或. yml
)中设置以下属性:
spring.main.web-application-type=none
如果您的类路径包含启动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
文件中,作为启动时的命令行参数等)。