Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

Java/Spring error: 'create()' in 'reactor.netty.http.server.HttpServer' cannot be applied to '(java.lang.String, int)'

I am doing a Java / Spring course. Here is the code:

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()
}

This is where the error occurs

error: 'create()' in 'reactor.netty.http.server.HttpServer' cannot be applied to '(java.lang.String, int)'

enter image description here

question from:https://stackoverflow.com/questions/65870267/java-spring-error-create-in-reactor-netty-http-server-httpserver-cannot-b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should create the server as follows:

 HttpServer.create()
           .host("0.0.0.0")
           .port(8080)
           .handle((req, res) -> res.sendString(Flux.just("hello")))
           .bind()
           .block();

The method create() is the only one available in HttpServer. The create with two parameters must have existed in a previous version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...