我已经建立了一个临时的github项目,以解决一个爱好项目,以学习反应性Java。 https://github.com/mikepc/mongodb-reactive-tmp
我最大的问题是使路由器正确配置。
路由器:
@Configuration
public class SponsoredEventRouter {
@Bean
public RouterFunction<ServerResponse> route(SponsoredEventHandler handler){
return RouterFunctions
.route(POST("/events").and(accept(MediaType.APPLICATION_JSON)), handler::createSponsoredEvent);
}
}
处理程序:
@Slf4j
@Component
public class SponsoredEventHandler {
private final SponsoredEventService sponsoredEventService;
public SponsoredEventHandler(SponsoredEventService sponsoredEventService) {
this.sponsoredEventService = sponsoredEventService;
}
public Mono<ServerResponse> createSponsoredEvent(ServerRequest req) {
Mono<SponsoredEventRequest> newEventRequest = req.bodyToMono(SponsoredEventRequest.class);
return ok()
.contentType(MediaType.APPLICATION_JSON)
.body(this.sponsoredEventService.createSponsoredEvent(newEventRequest), SponsoredEvent.class);
}
}
POM在项目中
问题如下: 1)IDEA呈红色波浪状显示“无法自动装配。找不到'SponsoredEventHandler'类型的bean。” 2)路由未注册。当我点击/ events端点时,它将返回一个基本的404错误。
答案 0 :(得分:0)
好吧,我找到了答案:包装没有正确对齐。所有软件包都在层次结构的同一级别上。这真是一个魔鬼,但是现在我注意到了,它运行良好。感谢您阅读此<3
的任何人