my.queues=foo,bar,baz
Spring может преобразовать это в List<String>
.
@Bean
public Declarables queues(@Value("${my.queues}") List<String> queues) {
return new Declarables(queues
.stream()
.map(q -> new Queue(q))
.collect(Collectors.toList())
.toArray(new Queue[0]));
}
EDIT
Для полной картины:
@Bean
public Declarables declarables(@Value("${my.queues}") List<String> queues,
@Value("${my.exchange}") String exch,
@Value("${my.routing.keys}") List<String> routingKeys) {
List<Declarable> declarables = queues
.stream()
.map(q -> new Queue(q))
.collect(Collectors.toList());
declarables.add(new DirectExchange(exch));
for (int i = 0; i < routingKeys.size(); i++) {
declarables.add(new Binding(queues.get(i), DestinationType.QUEUE, exch,
routingKeys.get(i), null));
}
return new Declarables(declarables
.toArray(new Declarable[0]));
}
my.queues=foo,bar,baz
my.exchange=qux
my.routing.keys=rk1,rk2,rk3