protected void setLogLevels(LoggingSystem system, Environment environment) { if (!(environment instanceof ConfigurableEnvironment)) { return; } Binder binder = Binder.get(environment); Map<String, String[]> groups = getGroups(); binder.bind(LOGGING_GROUP, STRING_STRINGS_MAP.withExistingValue(groups)); Map<String, String> levels = binder.bind(LOGGING_LEVEL, STRING_STRING_MAP) .orElseGet(Collections::emptyMap); levels.forEach((name, level) -> { String[] groupedNames = groups.get(name); if (ObjectUtils.isEmpty(groupedNames)) { setLogLevel(system, name, level); } else { setLogLevel(system, groupedNames, level); } }); }
protected void setLogLevels(LoggingSystem system, Environment environment) { Map<String, String> levels = Binder.get(environment) .bind("logging.level", STRING_STRING_MAP).orElseGet(Collections::emptyMap); for (Entry<String, String> entry : levels.entrySet()) { setLogLevel(system, environment, entry.getKey(), entry.getValue().toString()); } }
/** * Extract the raw content based on the specified {@link PropertySource}. * @param propertySource the property source to use * @return the raw content */ protected Map<String, Object> extractContent(PropertySource<?> propertySource) { return new Binder(ConfigurationPropertySources.from(propertySource)) .bind("", STRING_OBJECT_MAP).orElseGet(LinkedHashMap::new); }
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); } }
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("Error opening logging config file " + logConfig, ex); } } }
protected void setLogLevels(LoggingSystem system, Environment environment) { Map<String, String> levels = Binder.get(environment) .bind("logging.level", STRING_STRING_MAP).orElseGet(Collections::emptyMap); for (Entry<String, String> entry : levels.entrySet()) { setLogLevel(system, environment, entry.getKey(), entry.getValue().toString()); } }
private boolean hasChildProperties(ConfigurableEnvironment environment, String name) { Map<String, Object> properties = Binder.get(environment) .bind(name, STRING_OBJECT_MAP).orElseGet(Collections::emptyMap); return !properties.isEmpty(); }
@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; }
@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; }
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); } }
private Set<String> bind(Binder binder, String name) { return asSet(binder.bind(name, Bindable.listOf(String.class)).map(this::cleanup) .orElseGet(ArrayList::new)); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { Map<String, String> subProperties = Binder.get(context.getEnvironment()) .bind(ZOOKEEPER_DEPENDENCIES_PROP, STRING_STRING_MAP).orElseGet(Collections::emptyMap); if (!subProperties.isEmpty()) { return ConditionOutcome.match("Dependencies are defined in configuration"); } Boolean dependenciesEnabled = context.getEnvironment() .getProperty("spring.cloud.zookeeper.dependency.enabled", Boolean.class, false); if (dependenciesEnabled) { return ConditionOutcome.match("Dependencies are not defined in configuration, but switch is turned on"); } return ConditionOutcome.noMatch("No dependencies have been passed for the service"); }
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("Error opening logging config file " + logConfig, ex); } } }
private WebApplicationType getWebApplicationType( MergedContextConfiguration configuration) { ConfigurationPropertySource source = new MapConfigurationPropertySource( TestPropertySourceUtils.convertInlinedPropertiesToMap( configuration.getPropertySourceProperties())); Binder binder = new Binder(source); return binder .bind("spring.main.web-application-type", Bindable.of(WebApplicationType.class)) .orElseGet(this::deduceWebApplicationType); }
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("DynamoDB"); Environment environment = context.getEnvironment(); Binder binder = Binder.get(environment); DynamoProperties dynamoProperties = binder.bind("spring.data.dynamodb", DynamoProperties.class) .orElseGet(DynamoProperties::new); String accessKey = dynamoProperties.getAccessKey(); String secretKey = dynamoProperties.getSecretKey(); if (StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey)) { return ConditionOutcome.match( message.available("found accessKey and secretKey property")); } return ConditionOutcome.noMatch( message.because("not found accessKey and secretKey property")); } }
SpringApplication application) { Binder.get(environment).bind("vcap.services", STRING_OBJECT_MAP) .orElseGet(Collections::emptyMap); if (!hasChildProperties(environment, "vcap.services")) { return;