Top Description Constructors Methods
org.eclipse.microprofile.config

public final Class ConfigProvider

extends Object
Class Inheritance
Imports
org.eclipse.microprofile.config.spi.ConfigProviderResolver

This is the central class to access a Config.

A Config provides access to the application's configuration. It may have been automatically discovered, or manually created and registered.

The default usage is to use getConfig() to automatically pick up the configuration for the current thread's context class loader.

A configuration consists of information collected from the registered configuration sources, combined with the set of registered converters. The configuration sources get sorted according to their ordinal value. Thus it is possible to override a lower-priority configuration source with a higher-priority one.

It is also possible to register custom configuration sources to flexibly extend the configuration mechanism. For example, a configuration source could be provided which reads configuration values from a database table.

Example:

String restUrl = ConfigProvider.getConfig().getValue("myproject.some.remote.service.url", String.class);
Integer port = ConfigProvider.getConfig().getValue("myproject.some.remote.service.port", Integer.class);

For more advanced use cases (e.g. registering a manually created Config instance), please see ConfigProviderResolver#registerConfig(Config, ClassLoader) and ConfigProviderResolver#getBuilder().

Authors
Mark Struberg, Romain Manni-Bucau, Emily Jiang, Viktor Klang

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Config

Returns:

the configuration instance for the thread context class loader
getConfig
()

Get the configuration corresponding to the current application, as defined by the calling thread's context class loader.

public static Config

Returns:

the configuration instance for the given class loader
getConfig
(ClassLoader
the Classloader used to register the configuration instance
cl
)

Get the configuration for the application corresponding to the given class loader instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ConfigProviderback to summary
private ConfigProvider()

Method Detail

getConfigback to summary
public static Config getConfig()

Get the configuration corresponding to the current application, as defined by the calling thread's context class loader.

The Config instance will be created and registered to the context class loader if no such configuration is already created and registered.

Each class loader corresponds to exactly one configuration.

Returns:Config

the configuration instance for the thread context class loader

getConfigback to summary
public static Config getConfig(ClassLoader cl)

Get the configuration for the application corresponding to the given class loader instance.

The Config instance will be created and registered to the given class loader if no such configuration is already created and registered.

Each class loader corresponds to exactly one configuration.

Parameters
cl:ClassLoader

the Classloader used to register the configuration instance

Returns:Config

the configuration instance for the given class loader