次の方法で共有


ConfigurationBuilder Class

  • java.lang.Object
    • com.azure.core.util.ConfigurationBuilder

public final class ConfigurationBuilder

Builds Configuration with external source.

Constructor Summary

Constructor Description
ConfigurationBuilder()

Creates ConfigurationBuilder.

ConfigurationBuilder(ConfigurationSource source)

Creates ConfigurationBuilder with configuration source.

ConfigurationBuilder(ConfigurationSource source, ConfigurationSource systemPropertiesConfigurationSource, ConfigurationSource environmentConfigurationSource)

Creates ConfigurationBuilder with configuration sources for explicit configuration, system properties and environment configuration sources.

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.

ConfigurationBuilder putProperty(String name, String value)

Adds property to the configuration source.

ConfigurationBuilder 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:

source - Custom ConfigurationSource containing known Azure SDK configuration properties.

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:

source - Custom ConfigurationSource containing known Azure SDK configuration properties
systemPropertiesConfigurationSource - ConfigurationSource containing known Azure SDK system properties.
environmentConfigurationSource - ConfigurationSource containing known Azure SDK environment variables.

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:

Root Configuration with shared properties.

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:

path - relative path from root(String rootPath) to client section.

Returns:

Client Configuration capable of reading client-specific and shared properties.

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:

name - Property name.
value - Property value.

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:

rootPath - absolute root path, can be null.

Returns:

ConfigurationBuilder instance for chaining.

Applies to