Monday, September 30, 2013

Spring: Inject comma separated values into a List

1. Define your properties in a properties file

gestures=rock, paper, scissors, lizard, spock

2. Ensure that you have your context property placeholder defined in your context xml

<context:property-placeholder location="classpath*:*.properties"/>

3. Finally in your java class, you can inject the value when you define the class member:

 @Value("#{'${gestures}'.split(',')}")
 private List<String> gameGestures;


3 comments: