Java property files using the key as another key value, possibly

I would like to know if there is a way to use the key as another key value in the .properties files.

For example, is it possible, or is there another way to achieve something like this?

key = another_key app.name=Stack Over Flow app.title.welcome=Welcome to {app.name} 

so when i get the value of app.title.welcome it should be " Welcome to Stack Over Flow "

+4
source share
4 answers

The Apache Commons Configuration project has an implementation that can perform variable interpolation.

Read the section called Variable Interpolation

 application.name = Killer App application.version = 1.6.2 application.title = ${application.name} ${application.version} 

You will need this third-party library in your class path, but on the other hand, you don’t have to worry about writing another implementation for this :)

You may like to read How To Properties .

+4
source

You can check the Apache Commons Configuration . He does what you seek and more .

+2
source

With java.util.Properties - no. But if you write the correct resolver, it is. And to write that the resolver will not be so hard. Just find {..} in each value and whenever you meet find that key.

+1
source

You can simply write app.title.welcome=Welcome to {0} and pass app.name as a parameter in the Java code.

0
source

Source: https://habr.com/ru/post/1347619/


All Articles