如何自动装配弹簧流云绑定

时间:2017-09-19 15:24:27

标签: java spring spring-boot spring-cloud spring-messaging

我在error

中定义了notificationapplication.yml个绑定
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.*仅允许配置频道。但是没有创造它。

1 个答案:

答案 0 :(得分:2)

您确定拥有@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 {