如何将队列、交换和绑定的所有声明聚合到Kotlin中的集合?
我有正在工作的Java代码,它以列表的形式返回声明:
@Bean
public List<Declarable> declaration() {
return Arrays.asList(
new Queue("queue-1"),
new Queue("queue-2"),
new Queue("queue-3"),
new Queue("queue-4"),
new FanoutExchange("fanout-1"),
new FanoutExchange("fanout-2"));
}但Kotlin上的相同代码不起作用:
@Bean
open fun declaration(): List<Declarable> {
return Arrays.asList(
Queue("queue-1"),
Queue("queue-2"),
Queue("queue-3"),
Queue("queue-4"),
FanoutExchange("fanout-1"),
FanoutExchange("fanout-2"))
}更新
在Java中,我有SpringVersion1.5.9和Kotlin2.1.1。因为2.1不推荐使用List<Declarable>并使用可执行命令
@Bean
open fun declaration(): Declarables {
return Declarables(listOf(
Queue("queue-1"),
Queue("queue-2"),
Queue("queue-3"),
Queue("queue-4")))
}发布于 2019-03-15 13:57:06
从2.1开始,使用Declarables来包装列表,而不是原始列表。
使用List<Declarable>是不可取的;它仍然是受支持的,但是您必须将admin的declareCollections属性设置为true。
https://stackoverflow.com/questions/55179049
复制相似问题