我正在嘗試使用Spring Cloud Stream來發布和使用Kafka消息。我一直在關注文檔here on Accessing Bound Channels。我試圖在我的主題上使用頻道的自定義名稱,所以當我嘗試注入時有一個@Qualifier,但是Spring找不到相關的bean。它說「對於每個綁定的接口,Spring Cloud Stream將生成一個實現接口的bean」,但是自動佈線不起作用。爲什麼不能春天找到spring雲流創建的@Source bean頻道?
我得到的錯誤是「com中構造函數的參數0 ... MessagingManager需要一個'org.springframework.messaging.MessageChannel'類型的bean無法找到。」
我試着在MessagingManager構造函數之前使用@Autowired,就像在例子中那樣,但是後來在bean工廠裏得到了一個類似的錯誤,因爲它們中有2個,所以我把它拿出來,並且得到了當前的錯誤。
這可能是複雜的,我試圖使用一個處理器。
這是我的組件。我和春天開機運行,並試圖與這個來測試它:
@Component
public class StartupTester implements ApplicationListener<ContextRefreshedEvent> {
MessagingManager messagingManager;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
messagingManager.sendThingCreatedMessage(new ThingCreated("12345", "667788"));
}
}
@Component
public class MessagingManager {
private MessageChannel thingCreatedChannel;
public MessagingManager(@Qualifier(ThingChannelProcessor.THING_CREATED) MessageChannel output) {
thingCreatedChannel = output;
}
public void sendThingCreatedMessage(ThingCreated thingCreated) {
thingCreatedChannel.send(MessageBuilder.withPayload(thingCreated).build());
}
}
@Component
public interface ThingsChannelProcessor extends Processor {
String THING_REQUEST = "thing-request";
String THING_CREATED = "thing-created";
@Input(THING_REQUEST)
SubscribableChannel thingsRequest();
@Output(THING_CREATED)
MessageChannel thingCreated();
}
而且我也有@EnableBinding(ThingsMessagingManager.class)在其上標註有@SpringBootApplication我的主類。
嘗試將接口作爲參數傳遞@EnableBinding(ThingsChannelProcessor.class) – RSM