Skip to content

Spring WebFlux RouterFunction cannot add subclass of ServerResponse #33851

@mitu2

Description

@mitu2

my code

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.EntityResponse;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import java.util.Collections;

import static org.springframework.web.reactive.function.server.RouterFunctions.route;


@Bean
RouterFunction<ServerResponse> routerFunction() {
    return route()
            .GET("test", request -> {
               // `EntityResponse` or `RenderingResponse` 
                return EntityResponse
                        .fromObject(Collections.singletonMap("Key", "Value"))
                        .build();
            })
            .build();
}

ide error tips

Bad return type in lambda expression: Mono<EntityResponse<Map<String, String>>> cannot be converted to Mono<ServerResponse>

Is this normal? Or is this API not intended for this location. I didn't mention it when I read the document

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions