In our applications we are using property files very much. Since a few months I have started to learn Guava and I liked it a lot actually.
What is the best way to create a Map<String, Datasource> ?
The property file format is not strict. It can be changed if It can be expressed better with another format?
Sample property file:
datasource1.url=jdbc:mysql://192.168.11.46/db1
datasource1.password=password
datasource1.user=root
datasource2.url=jdbc:mysql://192.168.11.45/db2
datasource2.password=password
datasource2.user=root
Properties class is a subclass of HashTable, which in turn implements Map.
You load it as usual with:
edit: Ok so you want to transform it to Map<String, Datasource> 😉
There’s probably an easier way, but this should work 🙂
Still you’re better off with json or xml. You can also load properties of different datasources from different files.
edit2: with less guava, more java: