Java 类org.springframework.boot.context.properties.bind.Bindable 实例源码
项目:loc-framework
文件:PrefixPropertyCondition.java
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String prefix = (String) attribute(metadata, "prefix");
Class<?> value = (Class<?>) attribute(metadata, "value");
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
try {
new Binder(ConfigurationPropertySources.from(environment.getPropertySources()))
.bind(prefix, Bindable.of(value))
.orElseThrow(
() -> new FatalBeanException("Could not bind DataSourceSettings properties"));
return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix));
} catch (Exception e) {
//ignore
}
return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix));
}
项目:spring-cloud-commons
文件:PropertySourceBootstrapConfiguration.java
private void reinitializeLoggingSystem(ConfigurableEnvironment environment,
String oldLogConfig, LogFile oldLogFile) {
Map<String, Object> props = Binder.get(environment)
.bind("logging", Bindable.mapOf(String.class, Object.class)).orElseGet(Collections::emptyMap);
if (!props.isEmpty()) {
String logConfig = environment.resolvePlaceholders("${logging.config:}");
LogFile logFile = LogFile.get(environment);
LoggingSystem system = LoggingSystem
.get(LoggingSystem.class.getClassLoader());
try {
ResourceUtils.getURL(logConfig).openStream().close();
// Three step initialization that accounts for the clean up of the logging
// context before initialization. Spring Boot doesn't initialize a logging
// system that hasn't had this sequence applied (since 1.4.1).
system.cleanUp();
system.beforeInitialize();
system.initialize(new LoggingInitializationContext(environment),
logConfig, logFile);
}
catch (Exception ex) {
PropertySourceBootstrapConfiguration.logger
.warn("Logging config file location '" + logConfig
+ "' cannot be opened and will be ignored");
}
}
}
项目:spring-cloud-stream
文件:EnvironmentEntryInitializingTreeMap.java
@Override
public T get(Object key) {
if (!this.delegate.containsKey(key) && key instanceof String) {
T entry = BeanUtils.instantiateClass(entryClass);
Binder binder = new Binder(ConfigurationPropertySources.get(environment),new PropertySourcesPlaceholdersResolver(environment),this.conversionService);
binder.bind(defaultsPrefix, Bindable.ofInstance(entry));
this.delegate.put((String) key, entry);
}
return this.delegate.get(key);
}
项目:spring-cloud-stream
文件:EnvironmentEntryInitializingTreeMap.java
@Override
public T put(String key, T value) {
// boot 2 call this first
Binder binder = new Binder(ConfigurationPropertySources.get(environment),new PropertySourcesPlaceholdersResolver(environment),this.conversionService);
binder.bind(defaultsPrefix, Bindable.ofInstance(value));
return this.delegate.put(key, value);
}
项目:spring-cloud-commons
文件:PropertySourceBootstrapConfiguration.java
private void insertPropertySources(MutablePropertySources propertySources,
CompositePropertySource composite) {
MutablePropertySources incoming = new MutablePropertySources();
incoming.addFirst(composite);
PropertySourceBootstrapProperties remoteProperties = new PropertySourceBootstrapProperties();
Binder.get(environment(incoming)).bind("spring.cloud.config", Bindable.ofInstance(remoteProperties));
if (!remoteProperties.isAllowOverride() || (!remoteProperties.isOverrideNone()
&& remoteProperties.isOverrideSystemProperties())) {
propertySources.addFirst(composite);
return;
}
if (remoteProperties.isOverrideNone()) {
propertySources.addLast(composite);
return;
}
if (propertySources
.contains(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
if (!remoteProperties.isOverrideSystemProperties()) {
propertySources.addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
composite);
}
else {
propertySources.addBefore(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
composite);
}
}
else {
propertySources.addLast(composite);
}
}
项目:spring-cloud-commons
文件:HostInfoEnvironmentPostProcessor.java
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
InetUtilsProperties target = new InetUtilsProperties();
ConfigurationPropertySources.attach(environment);
Binder.get(environment).bind(InetUtilsProperties.PREFIX,
Bindable.ofInstance(target));
try (InetUtils utils = new InetUtils(target)) {
return utils.findFirstNonLoopbackHostInfo();
}
}
项目:spring-cloud-aws
文件:AmazonRdsDatabaseAutoConfiguration.java
@SuppressWarnings("unchecked")
private Map<String, Map<String, String>> getDbInstanceConfigurations() {
Map<String, Object> subProperties = Binder.get(this.environment)
.bind(PREFIX, Bindable.mapOf(String.class, Object.class)).orElseGet(Collections::emptyMap);
Map<String, Map<String, String>> dbConfigurationMap = new HashMap<>(subProperties.keySet().size());
for (Map.Entry<String, Object> subProperty : subProperties.entrySet()) {
String instanceName = subProperty.getKey();
if (!dbConfigurationMap.containsKey(instanceName)) {
dbConfigurationMap.put(instanceName, new HashMap<>());
}
Object value = subProperty.getValue();
if (value instanceof Map) {
Map<String, String> map = (Map) value;
for (Map.Entry<String, String> entry : map.entrySet()) {
dbConfigurationMap.get(instanceName).put(entry.getKey(), entry.getValue());
}
} else if (value instanceof String) {
String subPropertyName = extractConfigurationSubPropertyName(subProperty.getKey());
if (StringUtils.hasText(subPropertyName)) {
dbConfigurationMap.get(instanceName).put(subPropertyName, (String) subProperty.getValue());
}
}
}
return dbConfigurationMap;
}
项目:loc-framework
文件:LocBaseAutoConfiguration.java
protected <T> T resolverSetting(Class<T> clazz, MutablePropertySources propertySources) {
return new Binder(ConfigurationPropertySources.from(propertySources))
.bind("loc", Bindable.of(clazz))
.orElseThrow(() -> new FatalBeanException("Could not bind DataSourceSettings properties"));
}
项目:spring-cloud-commons
文件:EnvironmentUtils.java
public static Map<String, String> getSubProperties(Environment environment,
String keyPrefix) {
return Binder.get(environment)
.bind(keyPrefix, Bindable.mapOf(String.class, String.class))
.orElseGet(Collections::emptyMap);
}
项目:spring-boot-admin
文件:SpringBootAdminClientEnabledCondition.java
private ClientProperties getClientProperties(ConditionContext context) {
Iterable<ConfigurationPropertySource> sources = ConfigurationPropertySources.get(context.getEnvironment());
ClientProperties clientProperties = new ClientProperties();
new Binder(sources).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties));
return clientProperties;
}