-
Notifications
You must be signed in to change notification settings - Fork 2k
Configuration
Azure Core offers the Configuration
class as a standard way to load, store, and share environment and runtime application configuration.
Configuration
has APIs to get, check existence, put, and remove key-value properties.
Configuration
offers multiple get APIs which offer different levels of convenience but all use the same root logic. Initially the configuration which check to see if it already contains the value in its in-memory cache, if it doesn't it will then attempt to load it from the environment checking Java properties (System.getProperty
) and the environment (System.getenv
), in that order, accepting the first non-null value loaded. The default get will return the value as a String with get or default and get and transform convenience APIs also being available.
Examples
Load SERVER_ENDPOINT
String serverEndpoint = configuration.load("SERVER_ENDPOINT");
Load SERVER_ENDPOINT with default value
String serverEndpoint = configuration.load("SERVER_ENDPOINT", "<default value>");
Load SERVER_ENDPOINT and transform to URL
URL serverEndpoint = configuration.load("SERVER_ENDPOINT", endpoint -> {
try {
return new URL(endpoint);
} catch (MalformedURLException ex) {
return null;
}
});
Configuration
offers a single put API to directly set a key-value property without doing an environment look-up. This provides the ability to insert runtime properties into the configuration without having to update the environment.
Configuration
has the ability to be scope preventing application properties from leaking into other areas of an application.
Configuration
as a singleton global configuration accessible using Configuration.getGlobalConfiguration()
that will be used as a default in most locations when a Configuration
isn't supplied. Updating this will allow for the changes to be shared in all spots where the global configuration is used.
Constructing a Configuration
instance will create a scoped configuration that is used only in location where it is passed into APIs using configuration. This will allow for application configuration to be scoped while retaining its ability to be shared across multiple locations.
In some situation you may not want Configuration
to attempt to load from the environment or affect execution of an application, for this reason a special Configuration.NONE
is available. This special configuration no-ops all operations and will always return null when get is used. This will prevent APIs that accept configuration from using it to modify their behavior/execution.
Example
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers