4

I have next application.properties file:

cassandra.connection.hosts[0]=host1.lab.org
cassandra.connection.hosts[1]=host2.lab.org

And I'm looking for a way to inject it as a list into a Spring bean - something like this:

@Value("${cassandra.connection.hosts}")
private List<String> hosts;

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'application': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List ru.croc.rosstat.csod.store.migrations.cli.Application.contactPoints; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cassandra.connection.nodes' in string value "${cassandra.connection.nodes}"

I know that it's possible to specify hosts in one comma separated line but it's not what I want. Another option is to use @ConfigurationProperties, it works. But is there a way to inject the list just by an annotation?

sedovav
  • 1,986
  • 1
  • 17
  • 28

0 Answers0