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.