Reputation: 1499
Scenario: application has an algorithm where some optimizations can be enabled. By default some are on, some are off. Is there a convenient way of implementing some kind of global property system in Java?
Requirements:
Alternatives:
-DenableOptimizationX=true
and System.getProperty("foo.bar.enableOptimizationX")
System.getenv("enableOptimizationX")
Which of these (or other) seems the best solution for this scenario?
Upvotes: 2
Views: 8740
Reputation: 3409
- it makes easy to look what all properties are being used.
- what is their current value,
- each deployment environment can have their own properties values(ex. qa, prod)
- you can logically group properties in different files.
propertiesMap
. In this class in static block initalize propertiesMap
with values from all properties file.
You can use propertiesMap
now from anywhere in code.You can access it as
PropertiesFactory.getPropertiesMap().get("key");
Update
If you want values to be update able , then propertiesMap needs to be mutable. You will need to run this program on server, where instance of propertiesMap is maintained and you can put method on this map when you want to override value of one of its key.
Upvotes: 3