如下,申明RouterFunction路由器函数时报错,信息是cannot resolve symbol RouterFunction,请问有大神知道为什么吗? public RouterFunction<ServletResponse> personFindAll(UserRepository userRepository){ Collection<User> users = userRepository.findAll(); }
import org.springframework.web.reactive.function.server.*;
可能是没有导入这个包,RouterFunction接口在这个包下
@Bean @Autowired //方法注入 public RouterFunction<ServerResponse> personFindAll(UserRepository userRepository){ return RouterFunctions.route(RequestPredicates.GET("/person/find/all"), request ->{ Collection<User> users = userRepository.findAll(); Flux<User> userFlux = Flux.fromIterable(users); return ServerResponse.ok().body(userFlux,User.class); }); }
参考对比一下这个