首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java/Spring错误:'reactor.netty.http.server.HttpServer‘中的'create()’不能应用于'(java.lang.String,int)‘

Java/Spring错误:'reactor.netty.http.server.HttpServer‘中的'create()’不能应用于'(java.lang.String,int)‘
EN

Stack Overflow用户
提问于 2021-01-24 19:59:37
回答 2查看 140关注 0票数 1

我正在学习一门Java / Spring课程。代码如下:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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()
}

这就是错误发生的地方

代码语言:javascript
复制
error: 'create()' in 'reactor.netty.http.server.HttpServer' cannot be applied to '(java.lang.String, int)'

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-24 20:04:57

您应该按如下方式创建服务器:

代码语言:javascript
复制
 HttpServer.create()
           .host("0.0.0.0")
           .port(8080)
           .handle((req, res) -> res.sendString(Flux.just("hello")))
           .bind()
           .block();

create()方法是HttpServer中唯一可用的方法。带有两个参数的create必须在以前的版本中存在。

票数 0
EN

Stack Overflow用户

发布于 2021-01-24 20:06:37

类HttpServer在create()方法中没有参数,设置时应该使用builder方法,例如:

代码语言:javascript
复制
 HttpServer.create()
       .host("127.0.0.1")
       .port(8080)
       .handle((req, res) -> res.sendString(Flux.just("hello")))
       .bind()
       .block();

查看更多here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65870267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档