1


I am loading a properties file with

@PropertySource("classpath:propFile.properties")

In this property file I have the following entry:

list.of.stg=a,b,c

Further, I do:

@Value("${list.of.stg}")public void setSomeList(...)
{in the method, the parameter has only the value a!!!}

Can you please indicate me a way of reaching the complete values of the

list.of.stg
Thank you!
DwB
  • 37,124
  • 11
  • 56
  • 82
Roxana
  • 1,569
  • 3
  • 24
  • 41

2 Answers2

1

Try with

@Value("#{T(org.springframework.util.StringUtils).commaDelimitedListToStringArray(environment['list.of.stg'])}")
Jose Luis Martin
  • 10,459
  • 1
  • 37
  • 38
0

As the the property value is passed in as a String you will have to use String#split but you can combine with Spring EL:

@Value("#{'${list.of.stg}'.split(',')}") 
public void setSomeList(List<String> list) {
   this.myList = list;
}

or simply on the class member variable

@Value("#{'${list.of.stg}'.split(',')}") 
private List<String> myList;

As always when using the @PropertySource annotation, don't forget to create a PropertyPlaceholderConfigurer @Bean to load the necessary property file(s).

Related: @Value and ArrayList

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Thank you for the answer - valid indeed. However, the site allows me to 'tick' only one answer. I heve chosen the one given by Jose beucause you already have a looot of points:) sorry!:0 – Roxana Mar 15 '13 at 15:25