有下列代码:
@Autowired
AuthHandler authHandler;
RouterFunction<ServerResponse> doctorRouter =
RouterFunctions.route()
.path("/doctors", b1 -> b1
.nest(accept(MediaType.APPLICATION_JSON), b2 -> b2
.GET("/{id}", request -> ServerResponse.ok()
.body(feignService.getDoctorById(request.headers().header("Authorization").get(0), Integer.valueOf(request.pathVariable("id"))),
String.class)
)
.POST(authHandler::loginAuthentication)
))
.build();
当起动spring程序时报authHandler
为空
但是当把代码修改为如下:
RouterFunction<ServerResponse> doctorRouter(){
return RouterFunctions.route()
.path("/doctors", b1 -> b1
.nest(accept(MediaType.APPLICATION_JSON), b2 -> b2
.GET("/{id}", request -> ServerResponse.ok()
.body(feignService
.getDoctorById(request.headers().header("Authorization").get(0), Integer.valueOf(request.pathVariable("id"))),
String.class)
)
.POST(authHandler::loginAuthentication)
))
.build();
}
这里spring起动成功,有哪位大神知道原因?敬请留言。