I'm not quite clear on what you are trying to accomplish, what I do suspect from following the flow in your code is that you want to get the value for the
key property at runtime. This is done using the
-Dkey=value flag while invoking your program at the command line.
The code to accomplish this feature is as follows:
And we invoke the application at the command-line as follows:
java -Dkey=dynamicProperty DynamicProperties
Output:
foo=dynamicProperty
But then again if that was not your intentions then Joanne Neal post is answer to your problem