Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properties in java - can we have comma-separated keys with single value?

I want to have multiple keys (>1) for a single value in a properties file in my java application. One simple way of doing the define each key in separate line in property file and the same value to all these keys. This approach increases the maintainability of property file. The other way (which I think could be smart way) is define comma separated keys with the value in single line. e.g.

  key1,key2,key3=value

Java.util.properties doesn't support this out of box. Does anybody did simillar thing before? I did google but didn't find anything.

--manish

like image 228
manish Avatar asked Feb 01 '10 19:02

manish


People also ask

How read multiple values from properties in spring boot?

A Singleton in Spring Boot 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. properties is not used because it is implicitly included in the PropertySource by Spring Boot.

How do I get a list of properties in spring boot?

To see all properties in your Spring Boot application, enable the Actuator endpoint called env . This enables an HTTP endpoint which shows all the properties of your application's environment.


1 Answers

I'm not aware of an existing solution, but it should be quite straightforward to implement:

String key = "key1,key2,key3", val = "value";
Map<String, String> map = new HashMap<String, String>();
for(String k : key.split(",")) map.put(k, val); 
System.out.println(map);
like image 78
Fabian Steeg Avatar answered Oct 01 '22 23:10

Fabian Steeg