简体   繁体   English

RouterFunction无法注入处理程序bean

[英]RouterFunction not able to inject handler bean

I've set up a temporary github project to troubleshoot a hobby project to learn reactive java. 我已经建立了一个临时的github项目,对一个业余项目进行故障排除以学习反应性Java。 https://github.com/mikepc/mongodb-reactive-tmp https://github.com/mikepc/mongodb-reactive-tmp

My biggest problem is getting the router to configure properly. 我最大的问题是使路由器正确配置。

Router: 路由器:

@Configuration
public class SponsoredEventRouter {


    @Bean
    public RouterFunction<ServerResponse> route(SponsoredEventHandler handler){

        return RouterFunctions
                .route(POST("/events").and(accept(MediaType.APPLICATION_JSON)), handler::createSponsoredEvent);
    }

}

Handler: 处理器:

@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);


    }
}

The POM is in the project POM在项目中

Problems are the following: 1) IDEA is showing a red squiggly saying "Could not autowire. No beans of type 'SponsoredEventHandler' could be found." 问题如下:1)IDEA呈红色波浪状显示“无法自动装配。找不到'SponsoredEventHandler'类型的bean。” 2) The route is not being registered. 2)路由未注册。 When I hit the /events endpoint, it returns a basic 404 error. 当我命中/ events端点时,它返回一个基本的404错误。

Ok I found the answer: The packages were not aligned correctly. 好的,我找到了答案:包装没有正确对齐。 All of the packages were at the same level of the hierarchy. 所有软件包都在层次结构的同一级别上。 This was a devil to debug, but now I noticed it, it's working great. 这真是一个魔鬼,但是现在我注意到了,它运行良好。 Thank you for anyone who read this <3 感谢您阅读本《 <3》的任何人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM