我正在学习一门Java / Spring课程。代码如下:
package com.pinodev.helloServer;
import reactor.netty.http.server.HttpServer;
public class HelloServerApplication {
public static void main(String[] args) {
HttpServer server = HttpServer.create("localhost",8080);
}
}build.gradle:
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.pinodev'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
test {
useJUnitPlatform()
}这就是错误发生的地方
error: 'create()' in 'reactor.netty.http.server.HttpServer' cannot be applied to '(java.lang.String, int)'

发布于 2021-01-24 20:04:57
您应该按如下方式创建服务器:
HttpServer.create()
.host("0.0.0.0")
.port(8080)
.handle((req, res) -> res.sendString(Flux.just("hello")))
.bind()
.block();create()方法是HttpServer中唯一可用的方法。带有两个参数的create必须在以前的版本中存在。
发布于 2021-01-24 20:06:37
类HttpServer在create()方法中没有参数,设置时应该使用builder方法,例如:
HttpServer.create()
.host("127.0.0.1")
.port(8080)
.handle((req, res) -> res.sendString(Flux.just("hello")))
.bind()
.block();查看更多here
https://stackoverflow.com/questions/65870267
复制相似问题