ConfigurationBuilder Class
- java.
lang. Object - com.
azure. core. util. ConfigurationBuilder
- com.
public final class ConfigurationBuilder
Builds Configuration with external source.
Constructor Summary
Constructor | Description |
---|---|
ConfigurationBuilder() |
Creates |
ConfigurationBuilder(ConfigurationSource source) |
Creates |
ConfigurationBuilder(ConfigurationSource source, ConfigurationSource systemPropertiesConfigurationSource, ConfigurationSource environmentConfigurationSource) |
Creates |
Method Summary
Modifier and Type | Method and Description |
---|---|
Configuration |
build()
Builds root Configuration section. |
Configuration |
buildSection(String path)
Builds Configuration section that supports retrieving properties from client-specific section with fallback to root section for properties that can be shared between clients. |
Configuration |
putProperty(String name, String value)
Adds property to the configuration source. |
Configuration |
root(String rootPath)
Sets path to root configuration properties where shared Azure SDK properties are defined. |
Methods inherited from java.lang.Object
Constructor Details
ConfigurationBuilder
public ConfigurationBuilder()
Creates ConfigurationBuilder
.
configuration = new ConfigurationBuilder()
.putProperty("azure.sdk.client-name.connection-string", "...")
.root("azure.sdk")
.buildSection("client-name");
ConfigurationProperty<String> connectionStringProperty = ConfigurationPropertyBuilder.ofString("connection-string")
.build();
System.out.println(configuration.get(connectionStringProperty));
ConfigurationBuilder
public ConfigurationBuilder(ConfigurationSource source)
Creates ConfigurationBuilder
with configuration source.
Configuration configuration = new ConfigurationBuilder(new SampleSource(properties))
.root("azure.sdk")
.buildSection("client-name");
ConfigurationProperty<String> proxyHostnameProperty = ConfigurationPropertyBuilder.ofString("http.proxy.hostname")
.shared(true)
.build();
System.out.println(configuration.get(proxyHostnameProperty));
Parameters:
ConfigurationBuilder
public ConfigurationBuilder(ConfigurationSource source, ConfigurationSource systemPropertiesConfigurationSource, ConfigurationSource environmentConfigurationSource)
Creates ConfigurationBuilder
with configuration sources for explicit configuration, system properties and environment configuration sources. Use this constructor to customize known Azure SDK system properties and environment variables retrieval.
Parameters:
Method Details
build
public Configuration build()
Builds root Configuration section. Use it for shared properties only. To read client-specific configuration, use buildSection(String path) which can read per-client and shared properties.
// Builds shared Configuration only.
Configuration sharedConfiguration = new ConfigurationBuilder(new SampleSource(properties))
.root("azure.sdk")
.build();
Returns:
buildSection
public Configuration buildSection(String path)
Builds Configuration section that supports retrieving properties from client-specific section with fallback to root section for properties that can be shared between clients.
// Builds Configuration for <client-name> with fallback to shared properties.
configuration = new ConfigurationBuilder(new SampleSource(properties))
.root("azure.sdk")
.buildSection("client-name");
Parameters:
Returns:
putProperty
public ConfigurationBuilder putProperty(String name, String value)
Adds property to the configuration source. In case the source already contains property with the same name, the value will be overwritten with the new value passed.
configuration = new ConfigurationBuilder()
.putProperty("azure.sdk.client-name.connection-string", "...")
.root("azure.sdk")
.buildSection("client-name");
ConfigurationProperty<String> connectionStringProperty = ConfigurationPropertyBuilder.ofString("connection-string")
.build();
System.out.println(configuration.get(connectionStringProperty));
Parameters:
Returns:
ConfigurationBuilder
instance for chaining.root
public ConfigurationBuilder root(String rootPath)
Sets path to root configuration properties where shared Azure SDK properties are defined. When local per-client property is missing, Configuration falls back to shared properties.
Configuration configuration = new ConfigurationBuilder(new SampleSource(properties))
.root("azure.sdk")
.buildSection("client-name");
ConfigurationProperty<String> proxyHostnameProperty = ConfigurationPropertyBuilder.ofString("http.proxy.hostname")
.shared(true)
.build();
System.out.println(configuration.get(proxyHostnameProperty));
Parameters:
null
.
Returns:
ConfigurationBuilder
instance for chaining.Applies to
Azure SDK for Java