PrefixedProperties extends the java.util.Properties class and can be used as a normal Properties object. The advantage of PrefixedProperties is that you can define different environments and sub-environments for your properties to filter the right keys by an prefix/environment you set. The prefixes itself are separated by a dot. Each environment has it's own prefix. With that it is possible to have different values of properties for any environment.

PrefixedProperties has a fallback mechanism that returns the most specific value for an key if the key for the specified environment is not available.

Common use cases are:

  • Different credentials for databases per environment
  • Different cache configurations per environment
  • Different resource paths per environment

Further advantages of PrefixedProperties:

  • There is no need to duplicate properties only to have them in each environment. With the fallback mechanism it's enough to have the plain key working for all other environments that don't have a specific entry.
    This also means you can mix your none environment depended properties with your environment depended properties.
  • The advantage of having all properties for all environments within one file is that is that it's harder to forget an entry for an environment.
  • With PrefixedProperties it's also possible to have request-depended properties. You can change the prefix for just one Thread. All other threads can have there own environment configureationor use the default one.
  • To store the key-value pairs, PrefixedProperties uses a TrieMap. Instead of having handling with long strings that have all the same part at the beginning, PrefixedProperties uses a character-node-structure.
  • PrefixedProperties is thread save you can use it concurrently without any blocking. It uses state of the art concurrent readwrite locks.
  • You can use PrefixedProperties to load and store properties, xml or json files and it is also possible to use the normal java object serialization mechanism.
  • You can use PrefixedProperties within your Spring-Projects to configure your beans. PrefixedProperties comes with it's own PrefixedPropertiesPlaceholderConfigurer and PrefixedPropertyOverrideConfigurer.
  • PrefixedProperties provides you methods for automatically conversion of properties to primitives and arrays of primitives splitting comma values.
  • PrefixedProperties comes with an RessourceBundle to use it also for your message keys.