How to Reference Another Property in Java.Util.Properties

Can I reference another property in a properties file (use ${property})

You might want look at Apache Configuration,

http://commons.apache.org/configuration/

Among many features it supports is the Variable Interpolation.

Reference other variables in Java properties file

One of the options mentioned in the question that Michael linked to in his comment above that I feel may help you is eproperties. Looks pretty promising.

HTH!

Refer to one property from another?

To answer my own question, a quick peak at the code shows that Wicket loads properties using java.util.Properties, which simply parses a stream for key-value pairs. It does not do any property expansion/substitution the way that developers might expect based on their experience with tools like ANT.

There are alternatives to Properties, like Apache Commons Configuration, that perform expansion but Properties does not. Therefore, neither does Wicket - it simply loads the properties as they are written. The only substitution Wicket does is for model properties when a page is rendered, not for properties in the "properties file" sense of the word.

Spring properties that depend on other properties

Spring can combine properties

myDir=/path/to/mydir 
myFile=${myDir}/myfile.txt

You can also use a default value without defining your myFile in the properties at first:

Properties file

myDir=/path/to/mydir

In class:

@Value("#{myFile:${myDir}/myfile.txt}")
private String myFileName;


Related Topics



Leave a reply



Submit