/** * Returns list of values of the `type` field from the `spring.cloud.config.server.composite` collection. */ public static List<String> getCompositeTypeList(Environment environment) { return Binder.get(environment) .bind("spring.cloud.config.server", CompositeConfig.class) .get().getComposite().stream() .map(map -> (String)map.get("type")) .collect(Collectors.toList()); }
/** * Bind the environment to the {@link SpringApplication}. * @param environment the environment to bind */ protected void bindToSpringApplication(ConfigurableEnvironment environment) { try { Binder.get(environment).bind("spring.main", Bindable.ofInstance(this)); } catch (Exception ex) { throw new IllegalStateException("Cannot bind to SpringApplication", ex); } }
private Set<Profile> getProfilesActivatedViaProperty() { if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY) && !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) { return Collections.emptySet(); } Binder binder = Binder.get(this.environment); Set<Profile> activeProfiles = new LinkedHashSet<>(); activeProfiles.addAll(getProfiles(binder, INCLUDE_PROFILES_PROPERTY)); activeProfiles.addAll(getProfiles(binder, ACTIVE_PROFILES_PROPERTY)); return activeProfiles; }
private <P extends EnvironmentRepositoryProperties> P bindProperties( int index, Class<P> propertiesClass, Environment environment) { Binder binder = Binder.get(environment); String environmentConfigurationPropertyName = String.format("spring.cloud.config.server.composite[%d]", index); P properties = binder.bind(environmentConfigurationPropertyName, propertiesClass).orElseCreate(propertiesClass); properties.setOrder(index + 1); return properties; } }
@Bean @ConditionalOnMissingBean public TemplateRenderer templateRenderer(Environment environment) { Binder binder = Binder.get(environment); boolean cache = binder.bind("spring.mustache.cache", Boolean.class).orElse(true); TemplateRenderer templateRenderer = new TemplateRenderer(); templateRenderer.setCache(cache); return templateRenderer; }
private ClientProperties getClientProperties(ConditionContext context) { ClientProperties clientProperties = new ClientProperties(context.getEnvironment()); Binder.get(context.getEnvironment()).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties)); return clientProperties; } }
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); } }); }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); Binder.get(environment) .bind("spring.output.ansi.enabled", AnsiOutput.Enabled.class) .ifBound(AnsiOutput::setEnabled); AnsiOutput.setConsoleAvailable(environment .getProperty("spring.output.ansi.console-available", Boolean.class)); }
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()); } }
@Override public void contribute(Info.Builder builder) { Binder binder = Binder.get(this.environment); binder.bind("info", STRING_OBJECT_MAP).ifBound(builder::withDetails); }
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 bindEnvironmentIfNeeded(BeanDefinitionRegistry registry) { if (!bound) { // only bind once if (this.environment == null) { this.environment = new StandardEnvironment(); } Binder.get(environment).bind("spring.cloud.refresh", Bindable.ofInstance(this)); bound = true; } }
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 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(); } } }
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())) {
public ExposeExcludePropertyEndpointFilter(Class<E> endpointType, Environment environment, String prefix, String... exposeDefaults) { Assert.notNull(endpointType, "EndpointType must not be null"); Assert.notNull(environment, "Environment must not be null"); Assert.hasText(prefix, "Prefix must not be empty"); Binder binder = Binder.get(environment); this.endpointType = endpointType; this.include = bind(binder, prefix + ".include"); this.exclude = bind(binder, prefix + ".exclude"); this.exposeDefaults = asSet(Arrays.asList(exposeDefaults)); }
private Map<String, String> bindProperties() { Map<String, String> target; BindResult<Map<String, String>> bindResult = Binder.get(environment).bind("", STRING_STRING_MAP); if (bindResult.isBound()) { target = bindResult.get(); } else { target = new HashMap<>(); } return target; }
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 LocElasticJobProperties resolverJobProperties() { try { return Binder.get(environment) .bind("loc.elasticjob", Bindable.of(LocElasticJobProperties.class)) .orElseThrow( () -> new FatalBeanException("Could not bind DataSourceSettings properties")); } catch (Exception e) { //ignore log.error("Could not bind job properties, error message is {}", e.getMessage(), e); throw new FatalBeanException("Could not bind job properties", e); } }
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(); } } }