簡體   English   中英

如何自動裝配Spring Stream Cloud綁定

[英]How to autowire spring stream cloud bindings

我在application.yml定義了errornotification綁定

cloud:
  stream:
    bindings:
      error:
        destination: error
        binder: default
      notification:
        destination: notification
        binder: default

如何在組件中獲取這些bean?

我嘗試了這種方法:

@Component
class MyComponent {

   @Autowired
   @Qualified("notification")
   MessageChannel notificationChannel;
}

但是沒有找到notificationChanel

更新 cloud.stream.bindings.*僅允許配置通道。 但是不會創建它。

您確定您具有@EnableBinding和適當的接口來聲明@Input@Output嗎?

https://docs.spring.io/spring-cloud-stream/docs/Chelsea.SR2/reference/htmlsingle/index.html#_declaring_and_binding_channels

public interface Barista {

    @Input
    SubscribableChannel orders();

    @Output
    MessageChannel hotDrinks();

    @Output
    MessageChannel coldDrinks();
}

...
@EnableBinding(Barista.class)
public class CafeConfiguration {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM