Spring AMQP 无法为 return 列表 <Binding> 创建 bean
Spring AMQP cannot create bean to return a List<Binding>
我正在尝试使用 Spring AMQP,版本 2.1。2.release,创建主题交换的多个绑定。
我发现了这个问题:
里面好像有答案。我还找到了提供相同解决方案的 documention。
但是,当我在我的 Bean 中 return 列表时,没有创建绑定。如果我 return 一个单一的绑定,那么它确实有效。由于缺乏声誉,我无法对该问题添加评论。
这是我的代码:
@Bean
public TopicExchange topicExchange() {
return new TopicExchange("topicExchange");
}
@Bean
public Queue testQueue() {
return new Queue("testQueue");
}
@Bean
List<Binding> multipleBindings() {
return Arrays.asList(
BindingBuilder.bind(testQueue()).to(topicExchange()).with("t1"),
BindingBuilder.bind(testQueue()).to(topicExchange()).with("t2"));
}
@Bean
Binding singleBinding() {
return BindingBuilder.bind(testQueue()).to(topicExchange()).with("t3");
}
在这段代码中,我获得了 "t3" 主题绑定,但是当我查看 Rabbit 管理控制台时没有看到 "t1" 或 "t2"。
请帮忙,因为这段代码看起来很简单并且遵循文档。我错过了什么?
谢谢
您指的是非常古老的文档。根据您使用的版本,已经有一个 Declarables
容器而不是 List
可以使用:https://docs.spring.io/spring-amqp/docs/2.1.4.RELEASE/reference/#collection-declaration
我正在尝试使用 Spring AMQP,版本 2.1。2.release,创建主题交换的多个绑定。
我发现了这个问题:
里面好像有答案。我还找到了提供相同解决方案的 documention。
但是,当我在我的 Bean 中 return 列表时,没有创建绑定。如果我 return 一个单一的绑定,那么它确实有效。由于缺乏声誉,我无法对该问题添加评论。
这是我的代码:
@Bean
public TopicExchange topicExchange() {
return new TopicExchange("topicExchange");
}
@Bean
public Queue testQueue() {
return new Queue("testQueue");
}
@Bean
List<Binding> multipleBindings() {
return Arrays.asList(
BindingBuilder.bind(testQueue()).to(topicExchange()).with("t1"),
BindingBuilder.bind(testQueue()).to(topicExchange()).with("t2"));
}
@Bean
Binding singleBinding() {
return BindingBuilder.bind(testQueue()).to(topicExchange()).with("t3");
}
在这段代码中,我获得了 "t3" 主题绑定,但是当我查看 Rabbit 管理控制台时没有看到 "t1" 或 "t2"。
请帮忙,因为这段代码看起来很简单并且遵循文档。我错过了什么?
谢谢
您指的是非常古老的文档。根据您使用的版本,已经有一个 Declarables
容器而不是 List
可以使用:https://docs.spring.io/spring-amqp/docs/2.1.4.RELEASE/reference/#collection-declaration