-
Notifications
You must be signed in to change notification settings - Fork 18
ph config
Philip Helger edited this page Apr 23, 2021
·
18 revisions
A multi-source configuration manager, that can use system properties, environment variables, resources and application specific values to work with.
See ConfigFactory.getDefaultConfig ()
for the starting point. By default the following configurations sources are scanned in this order:
- System properties - priority 400
- Environment variables - priority 300
- if the system property
config.resource
or the environment variableCONFIG_RESOURCE
is present, and it points to an existing classpath resource, the first one matching is used - priority 200 or determined by the system propertyconfig.resource.priority
or the environment variableCONFIG_RESOURCE_PRIORITY
. Note: the file type is determined by the extension and defaults to "properties". - if the system property
config.resources
(note the trailing "s") or the environment variableCONFIG_RESOURCES
is present, and it points to an existing classpath resource, all matching ones are used - priority 200 or determined by the system propertyconfig.resources.priority
(also note the trailing "s") or the environment variableCONFIG_RESOURCES_PRIORITY
. Note: the file type is determined by the extension and defaults to "properties". - if the system property
config.file
or the environment variableCONFIG_FILE
is present, and it points to an existing file, it is used - priority 200 or determined by the system propertyconfig.file.priority
or the environment variableCONFIG_FILE_PRIORITY
. Note: the file type is determined by the extension and defaults to "properties". - if the system property
config.url
or the environment variableCONFIG_URL
is present, and it points to an existing URL, it is used - priority 200 or determined by the system propertyconfig.url.priority
or the environment variableCONFIG_URL_PRIORITY
. Note: the file type is determined by the extension and defaults to "properties". - a JSON file called
private-application.json
- this is mainly to have an easy way to override settings - priority 195. - a properties file called
private-application.properties
- this is mainly to have an easy way to override settings - priority 190. - all JSON files called
application.json
that are in the classpath - priority 185. - all properties files called
application.properties
that are in the classpath - priority 180. - all properties files called
reference.properties
that are in the classpath - priority 1.
- Note: the default configuration does NOT contain any custom configuration files.
- Note: JSON and Properties files are expected to be UTF-8 encoded
The JSON configuration file must be a single large object so it must start with "{" and end with "}". The JSON syntax is a bit relaxed and allows for unquoted names but other than that it is regular JSON.
Add the following to your pom.xml to use this artifact:
<dependency>
<groupId>com.helger.commons</groupId>
<artifactId>ph-config</artifactId>
<version>x.y.z</version>
</dependency>
On Twitter: Follow @philiphelger
Donation link: https://paypal.me/PhilipHelger
It is appreciated if you star the GitHub project if you like it.