skrimpy
skrimpy

Reputation: 1

convert properties file to hashmap in spring

I need to load all of the content of my properties file which looks something like this:

some.properties

key.1=this item needs to be loaded onto a hashmap
key.2=this item also needs to be loaded onto a hashmap
key.3=this item also needs to be loaded onto a hashmap
key.4=this item also needs to be loaded onto a hashmap

I want to know a way in which i can load all of the content from my properties file onto a hashmap. The actual content that is present against every key is very lengthy, so i cannot make my properties file as abc=aa,bb,cc and then load it onto my java class using the @Value annotation.

Also, I have around 40 keys in my properties file. So, im trying to use this approach, As i dont want to add @Value annotation separately for every value in my java class.

As, on my hashmap i will put in certain checks to load which keys and then set those parameters one by one into my variables and pass it for further processing.

I tried a lot of things load the properties file and convert it into a hashmap through spring, all i now know is that i can make use of Property Placeholder Configurer which could load all of the properties file. However, how do i access the content inside the properties file in my java class converting it onto a hashmap.

Any help will be highly appreciated.

Thanks!

Upvotes: 0

Views: 1573

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121282

Or I don't understand your question or it is very simple:

Properties props = new Properties().load(new FileInputStream([PROPERTIES_PATH]));
Map<String, String> map = new HashMap<String, String>(props);

Let's start from here! Maybe I can help you more, if give more concrete info

Upvotes: 1

Related Questions