1

Looking for a solution that will provide us more functionality within Spring properties such as:

  • nested structures
  • maps/lists
  • properties referencing other properties. Example:
    • city.name=Toronto
    • city.address=#{city.name}, 123 Ave SW

I tried EProperties (Google) and Commons Configurations (Apache) but doesn't seem to integrate very well with the Spring Framework.

Also, we're using Velocity to access properties using #springMessage("city.address"), so it needs to work for that.

Does anyone know how I can achieve the above by extending the default Properties capability?

partizan
  • 469
  • 1
  • 9
  • 22

1 Answers1

0

With newest versions of Spring you can use the PropertySource mechanism. You register all your PropertySource and the order in which they are searched and then you don't have to do anything, except perhaps add this to your XML:

<context:property-placeholder />

As long as you declare only one of these without specifying local property files (the "old way"), you will be able to reference property A as the value of property B, even if they are not in the same property source.

For nested structures this may help if you don't like the properties readability: https://stackoverflow.com/a/13470704/82609

For parsing problems you can easily handle lists and other stuff like that manually very easily: Reading a List from properties file and load with spring annotation @Value

Community
  • 1
  • 1
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419