Reputation: 4840
My application.yml contains:
spring:
someproperty: value1, value2
How to bind few values to one variable using @Value? Should I bind it to list or how?
Upvotes: 0
Views: 53
Reputation: 1147
Use spring expression language this way
@Value("#{'${spring.someproperty}'.split(',')}")
private List<String> properties;
Use List and split the comma separated values with split() method like it is done here https://www.mkyong.com/spring/spring-value-import-a-list-from-properties-file/
To pass the value to the app add the properties to the startup script:
When launching the app simply add this to the startup script -Dspring.someproperty=value1,value2 , e.g.
java -jar yourapp.jar -Dspring.someproperty=value1,value2
Upvotes: 2
Reputation: 1056
@Value("#{'${spring.someproperty}'.split(',')}")
private List<String> properties;
Upvotes: 1