最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Spring Web Flux route(GET..., handler::method) -> detects handler::method as an Object. Why? - Stack Overflow

programmeradmin5浏览0评论

I have a routerClass defined with a route( Request,handlerMethod) but when Im going to compile it detects the handler method as if it were an Object instead of a handler Method is there anything I miss here?.

Router Class:

import .springframework.beans.factory.annotation.Autowired;
import .springframework.context.annotation.Bean;
import .springframework.context.annotation.Configuration;
import .springframework.web.reactive.function.server.RouterFunction;
import .springframework.web.reactive.function.server.RouterFunctions;
import .springframework.web.reactive.function.server.ServerResponse;
import .springframework.web.servlet.function.RequestPredicates;
import .springframework.web.reactive.function.server.ServerRequest;


import com.scotiabank.app.controllers.Handler.AlumnoHandler;

import static .springframework.web.reactive.function.server.RouterFunctions.route;
import static .springframework.web.reactive.function.server.RequestPredicates.*;

@Configuration
public class AlumnoRouterFunctionConfig {
    
    
    @Bean
    public RouterFunction<ServerResponse> routes(AlumnoHandler handler){
        return route(GET("/api/alumnos/getAlumno"),handler::listar);
        
    }

}

Handler class:


import .springframework.beans.factory.annotation.Autowired;
import .springframework.http.MediaType;
import .springframework.stereotype.Component;
import .springframework.web.reactive.function.server.ServerRequest;
import .springframework.web.servlet.function.ServerResponse;

import com.scotiabank.app.business.AlumnoService;
import reactor.core.publisher.Mono;

import static .springframework.web.reactive.function.BodyInserters.*;


@Component
public class AlumnoHandler {
    @Autowired
    private AlumnoService alumnoService;
    
    public Mono<ServerResponse> listar (ServerRequest request){
        return alumnoService.getActiveAlumnos()
                .collectList()
                .flatMap(alumnos->{
                    if(alumnos.isEmpty()) {return Mono.just(ServerResponse.notFound().build());}
                    else {return Mono.just(ServerResponse.ok()
                            .contentType(MediaType.APPLICATION_JSON)
                            .body(fromObject(alumnos)));}
                });
    }

}

I tried changing the list method on the handler and searched I have to do something more so it is detected as a handler and not as an object. I also tried to auto wire but it equally detected as an object.

Thank you very much.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论