为什么 Spring 不能自动装配我的云流处理器? [英] Why can't Spring autowire my cloud stream Processor?
问题描述
我正在尝试从 spring-cloud-stream 实现一个基本的处理器.我之前在其他项目上做过这个,所以我认为我很熟悉.但这一次 Spring 在通过 @Autowire
创建我的处理器引用时遇到了一个问题,@Service
组件.
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.
我认为重要的部分是应用程序上的 @EnableBinding(my.class)
,但我有.
I thought the important piece was the @EnableBinding(my.class)
on the Application, but I have that.
错误是
No qualifying bean of type 'com.mycompany.config.BizSyncProcessor' available
我也尝试将 @Component
添加到 BizSyncProcessor
,但这没有任何区别.
I also tried adding an @Component
to the BizSyncProcessor
, but that made no difference.
以下是部分:
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);
}
}
推荐答案
@EnableBinding(BizSyncProcessor.class)
如果没有在应用程序类路径中提供一些 Binder 实现,就没有任何意义.正是该工具执行实际绑定并为我们提供特定的 bean 以进行依赖注入.
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.
是的...看起来文档中没有明确的句子必须存在 Binder 实现才能触发绑定接口代理并将其注册为 bean:http://cloud.spring.io/spring-cloud-static/spring-cloud-stream/2.1.0.RC3/single/spring-cloud-stream.html#_destination_binders
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
随意提出一个 GitHub 问题来询问这样的文档改进!
Feel free to raise a GitHub issue to ask ask such a doc improvement!
这篇关于为什么 Spring 不能自动装配我的云流处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!