It seems that java.util.Properties assumes one value per propery key. That is,
foo=1 foo=2
is not expected,
Is there a class for this kind of multi-value property sheet, which also provides the load method?
You add a slash ("\") to continue the value on the next line.
We use a singleton bean whose properties map to entries in 3 separate properties files. This is the main class to read properties from multiple properties files into an object in Spring Boot. We use @PropertySource and locations of the files in the classpath. The application.
The java.util.Properties class is a class which represents a persistent set of properties.The Properties can be saved to a stream or loaded from a stream.Following are the important points about Properties − Each key and its corresponding value in the property list is a string.
Try:
foo=1,2 String[] foos = properties.getProperty("foo").split(",");
The java.util.Properties function is pretty limited. If you want support list, you might want try PropertyConfiguration from Apache Commons Configuration,
http://commons.apache.org/configuration/userguide/howto_properties.html#Using_PropertiesConfiguration
With it, you can set any delimiters to your list and it will split for you automatically. You can also do other fancy things in properties file. For example,
foo=item1, item2 bar=${foo}, item3 number=123
You can retrieve it like this,
Configuration config = new PropertiesConfiguration("your.properties"); String[] items = config.getStringArray("bar"); // return {"item1", "item2", "item3"} int number = config.getInt("number", 456); // 456 is default value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With