4

I have multiple property file sources in my spring xml files, they have different order values and some are optional.

  • application.properties - in the classpath, holds the default (fallback) properties (lowest priority)
  • [HOSTNAME].properties - in the classpath, holds properties specific for that hostname (higher priority)
  • Property file loaded by value in jndi - location specified in via jndi, highest priority.

In other words, I can override the default properties set in application.properties with properties in .properties and override those values in turn by a property file whose location is looked up by jndi.

What I would like to have however is some way for spring to give my a list of the resolved values of all the properties. Anyone know how I can do this?

It's easy for me to get the value of a particular property but what I actually need is a list of all the resolved properties.

Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
  • Possible duplicate of [Spring: access all Environment properties as a Map or Properties object](https://stackoverflow.com/questions/23506471/spring-access-all-environment-properties-as-a-map-or-properties-object) – Cherry May 29 '17 at 02:24

1 Answers1

1

I have two suggestions:

  1. You can override the class PropertyPlaceholderConfigurer with method processProperties to populate all the resolved properties. An example is listed here.
  2. Since PropertyPlaceholderConfigurer implements Spring's Ordered interface, you can have multiple property place holders; then, assign them the order in the order that should be in your application. Finally, having been already extended the class, you will have access to all resolved properties in the order that should be loaded.
nobeh
  • 9,784
  • 10
  • 49
  • 66