if (value instanceof String) { value = environment.resolvePlaceholders((String) value);
if (value instanceof String) { value = environment.resolvePlaceholders((String) value);
private Set<String> asResolvedSet(String value, String fallback) { List<String> list = Arrays.asList(StringUtils.trimArrayElements( StringUtils.commaDelimitedListToStringArray((value != null) ? this.environment.resolvePlaceholders(value) : fallback))); Collections.reverse(list); return new LinkedHashSet<>(list); }
private List<Resource> getResource(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext, String locations) { List<Resource> resources = new LinkedList<>(); String[] configFileLocations = locations == null ? DEFAULT_PROFILE_CONFIG_FILE_LOCATIONS : StringUtils .commaDelimitedListToStringArray(locations); for (String location : configFileLocations) { location = applicationContext.getEnvironment().resolvePlaceholders(location); servletContext.log("Testing for YAML resources at: " + location); Resource resource = applicationContext.getResource(location); if (resource != null && resource.exists()) { resources.add(resource); } } return resources; }
protected void registerBeanDefinitions(AnnotationAttributes attributes, BeanDefinitionRegistry registry) { String prefix = environment.resolvePlaceholders(attributes.getString("prefix")); Class<? extends AbstractConfig> configClass = attributes.getClass("type"); boolean multiple = attributes.getBoolean("multiple"); registerDubboConfigBeans(prefix, configClass, multiple, registry); }
protected void registerBeanDefinitions(AnnotationAttributes attributes, BeanDefinitionRegistry registry) { String prefix = environment.resolvePlaceholders(attributes.getString("prefix")); Class<? extends AbstractConfig> configClass = attributes.getClass("type"); boolean multiple = attributes.getBoolean("multiple"); registerDubboConfigBeans(prefix, configClass, multiple, registry); }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (!environment.resolvePlaceholders("${spring.cloud.config.enabled:false}") .equalsIgnoreCase("true")) { if (!environment.getPropertySources().contains(this.propertySource.getName())) { environment.getPropertySources().addLast(this.propertySource); } } }
/** * Finish the initialization of this context's bean factory, * initializing all remaining singleton beans. */ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { // Initialize conversion service for this context. if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) { beanFactory.setConversionService( beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); } // Register a default embedded value resolver if no bean post-processor // (such as a PropertyPlaceholderConfigurer bean) registered any before: // at this point, primarily for resolution in annotation attribute values. if (!beanFactory.hasEmbeddedValueResolver()) { beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal)); } // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false); for (String weaverAwareName : weaverAwareNames) { getBean(weaverAwareName); } // Stop using the temporary ClassLoader for type matching. beanFactory.setTempClassLoader(null); // Allow for caching all bean definition metadata, not expecting further changes. beanFactory.freezeConfiguration(); // Instantiate all remaining (non-lazy-init) singletons. beanFactory.preInstantiateSingletons(); }
@Override public String resolvePlaceholders(String text) { return delegate.resolvePlaceholders(text); }
/** * Finish the initialization of this context's bean factory, * initializing all remaining singleton beans. */ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { // Initialize conversion service for this context. if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) { beanFactory.setConversionService( beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); } // Register a default embedded value resolver if no bean post-processor // (such as a PropertyPlaceholderConfigurer bean) registered any before: // at this point, primarily for resolution in annotation attribute values. if (!beanFactory.hasEmbeddedValueResolver()) { beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal)); } // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false); for (String weaverAwareName : weaverAwareNames) { getBean(weaverAwareName); } // Stop using the temporary ClassLoader for type matching. beanFactory.setTempClassLoader(null); // Allow for caching all bean definition metadata, not expecting further changes. beanFactory.freezeConfiguration(); // Instantiate all remaining (non-lazy-init) singletons. beanFactory.preInstantiateSingletons(); }
properties.load(new StringReader(environment.resolvePlaceholders(pair))); String propertiesLocation = environment.resolvePlaceholders(this.embeddedKafka.brokerPropertiesLocation()); Resource propertiesResource = context.getResource(propertiesLocation); if (!propertiesResource.exists()) { Properties p = new Properties(); p.load(in); p.forEach((key, value) -> properties.putIfAbsent(key, environment.resolvePlaceholders((String) value)));
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); } } }
.resolvePlaceholders("${spring.cloud.bootstrap.location:}"); Map<String, Object> bootstrapMap = new HashMap<>(); bootstrapMap.put("spring.config.name", configName);
@Override public void initialize(ConfigurableApplicationContext applicationContext) { CompositePropertySource composite = new CompositePropertySource( BOOTSTRAP_PROPERTY_SOURCE_NAME); AnnotationAwareOrderComparator.sort(this.propertySourceLocators); boolean empty = true; ConfigurableEnvironment environment = applicationContext.getEnvironment(); for (PropertySourceLocator locator : this.propertySourceLocators) { PropertySource<?> source = null; source = locator.locate(environment); if (source == null) { continue; } logger.info("Located property source: " + source); composite.addPropertySource(source); empty = false; } if (!empty) { MutablePropertySources propertySources = environment.getPropertySources(); String logConfig = environment.resolvePlaceholders("${logging.config:}"); LogFile logFile = LogFile.get(environment); if (propertySources.contains(BOOTSTRAP_PROPERTY_SOURCE_NAME)) { propertySources.remove(BOOTSTRAP_PROPERTY_SOURCE_NAME); } insertPropertySources(propertySources, composite); reinitializeLoggingSystem(environment, logConfig, logFile); setLogLevels(applicationContext, environment); handleIncludedProfiles(environment); } }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (!environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, true)) { return; } // don't listen to events in a bootstrap context if (environment.getPropertySources().contains(BOOTSTRAP_PROPERTY_SOURCE_NAME)) { return; } ConfigurableApplicationContext context = null; String configName = environment .resolvePlaceholders("${spring.cloud.bootstrap.name:bootstrap}"); for (ApplicationContextInitializer<?> initializer : event.getSpringApplication() .getInitializers()) { if (initializer instanceof ParentContextApplicationContextInitializer) { context = findBootstrapContext( (ParentContextApplicationContextInitializer) initializer, configName); } } if (context == null) { context = bootstrapServiceContext(environment, event.getSpringApplication(), configName); event.getSpringApplication().addListeners(new CloseContextOnFailureApplicationListener(context)); } apply(context, event.getSpringApplication(), environment); }
private String resolve(String value) { if (StringUtils.hasText(value) && this.resourceLoader instanceof ConfigurableApplicationContext) { return ((ConfigurableApplicationContext) this.resourceLoader).getEnvironment() .resolvePlaceholders(value); } return value; }
private String resolve(String value) { if (StringUtils.hasText(value) && this.resourceLoader instanceof ConfigurableApplicationContext) { return ((ConfigurableApplicationContext) this.resourceLoader).getEnvironment() .resolvePlaceholders(value); } return value; }
private <T> T getAttribute(Element element, String name, T defaultValue) { ConversionService conversionService = environment.getConversionService(); String value = element.getAttribute(name); String resolvedValue = environment.resolvePlaceholders(value); T attributeValue = StringUtils.hasText(resolvedValue) ? (T) conversionService.convert(resolvedValue, defaultValue.getClass()) : defaultValue; return attributeValue; }
@Override public void onApplicationEvent(ApplicationPreparedEvent event) { ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment(); if (StringUtils.hasText(environment.resolvePlaceholders("${dm.config.git.uri:}"))) { if (!environment.getPropertySources().contains(this.propertySource.getName())) { environment.getPropertySources().addLast(this.propertySource); } } }
protected void registerBeanDefinitions(AnnotationAttributes attributes, BeanDefinitionRegistry registry) { String prefix = environment.resolvePlaceholders(attributes.getString("prefix")); Class<? extends AbstractConfig> configClass = attributes.getClass("type"); boolean multiple = attributes.getBoolean("multiple"); registerDubboConfigBeans(prefix, configClass, multiple, registry); }