Why can't Spring autowire my cloud stream Processor?

孤者浪人 提交于 2019-12-11 19:31:02

问题


I'm trying to implement a basic Processor from spring-cloud-stream. I've done this before on other projects, so I thought I was familiar with it. But this time Spring is having a problem creating via @Autowire my Processor reference inside a @Service component.

I thought the important piece was the @EnableBinding(my.class) on the Application, but I have that.

The error is

No qualifying bean of type 'com.mycompany.config.BizSyncProcessor' available

I also tried adding an @Component to the BizSyncProcessor, but that made no difference.

Here are the pieces:

public interface BizSyncProcessor {

    String BUSINESS_IDS_INPUT = "updatedBusinessIdsIn";
    String BUSINESS_IDS_OUTPUT = "updatedBusinessIdsOut";

    @Output(BizSyncProcessor.BUSINESS_IDS_OUTPUT)
    MessageChannel writeUpdatedBusinessIds();

    @Input(BizSyncProcessor.BUSINESS_IDS_INPUT)
    MessageChannel readUpdatedBusinessIds();

}

@Service
public class BusinessService {

    @Autowired
    private BizSyncProcessor bizSyncProcessor;

    // methods which reference bizSyncProcessor's input and outputs
}

@EnableBinding(BizSyncProcessor.class)
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

回答1:


The @EnableBinding(BizSyncProcessor.class) does not have any sense without some Binder implementation presented in the application classpath. Exactly that tool does the actual binding and provides particular beans for us for dependency injection.

Yeah... Looks like there is no clear sentence in the Docs that Binder implementation must be present to trigger binding interface proxying and registering it as a bean: http://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.1.0.RC3/single/spring-cloud-stream.html#_destination_binders

Feel free to raise a GitHub issue to ask ask such a doc improvement!



来源:https://stackoverflow.com/questions/53818113/why-cant-spring-autowire-my-cloud-stream-processor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!