user26270
user26270

Reputation: 7074

Why can't Spring autowire my cloud stream Processor?

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

Upvotes: 0

Views: 329

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

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!

Upvotes: 1

Related Questions