当前位置: 首页>>代码示例>>Java>>正文


Java PropertySourcesPropertyResolver类代码示例

本文整理汇总了Java中org.springframework.core.env.PropertySourcesPropertyResolver的典型用法代码示例。如果您正苦于以下问题:Java PropertySourcesPropertyResolver类的具体用法?Java PropertySourcesPropertyResolver怎么用?Java PropertySourcesPropertyResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PropertySourcesPropertyResolver类属于org.springframework.core.env包,在下文中一共展示了PropertySourcesPropertyResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveProperties

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
/**
 * Resolves any {@link KafkaPropertyUtils#isNullValue(Object) null} property values in the {@code Map} using the
 * supplied {@code propertyResolver} and {@code Environment}.
 *
 * @param props
 * @param propertyResolver
 * @param env
 */
public static void resolveProperties(Map<String, Object> props, PropertySourcesPropertyResolver propertyResolver,
                                     Environment env) {
    props.entrySet().stream()
            .filter(entry -> isNullValue(entry.getValue()) || entry.getValue().toString().contains("${"))
            .forEach(entry -> {
                String resolvedValue = null;
                if (isNullValue(entry.getValue())) {
                    resolvedValue = env.getProperty(entry.getKey());
                    LOG.debug("Resolved kafka null property key [{}] to [{}]", entry.getKey(), resolvedValue);
                } else {
                    resolvedValue = entry.getValue().toString();
                }

                if (resolvedValue != null && resolvedValue.contains("${")) {
                    String placeholder = resolvedValue;
                    resolvedValue = propertyResolver.resolvePlaceholders(resolvedValue);
                    resolvedValue = env.resolvePlaceholders(resolvedValue);
                    LOG.debug("Resolved kafka property key [{}] with placeholder [{}] to [{}]",
                            entry.getKey(), placeholder, resolvedValue);
                }

                props.put(entry.getKey(), resolvedValue);
            });
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:33,代码来源:KafkaPropertyUtils.java

示例2: processNonEnumerablePropertySource

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private void processNonEnumerablePropertySource(PropertySource<?> source,
		PropertySourcesPropertyResolver resolver) {
	// We can only do exact matches for non-enumerable property names, but
	// that's better than nothing...
	if (this.nonEnumerableFallbackNames == null) {
		return;
	}
	for (String propertyName : this.nonEnumerableFallbackNames) {
		if (!source.containsProperty(propertyName)) {
			continue;
		}
		Object value = null;
		try {
			value = resolver.getProperty(propertyName, Object.class);
		}
		catch (RuntimeException ex) {
			// Probably could not convert to Object, weird, but ignorable
		}
		if (value == null) {
			value = source.getProperty(propertyName.toUpperCase());
		}
		putIfAbsent(propertyName, value, source);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:PropertySourcesPropertyValues.java

示例3: newMultiResourcePropertyResolver

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
/**
 * Creates a property resolver that pulls from multiple property resource
 * locations. The first "built-in" location must be successfully loaded, but
 * all other "custom" locations must load only if {code}allowMissing{code} is
 * false.
 *
 * @param allowMissing            true to allow custom resource locations to fail to load
 * @param builtInResourceLocation lowest precedence, required resource
 *                                location for properties
 * @param customResourceLocations additional resource locations for
 *                                properties, in increasing order of precedence
 * @return new property resolver
 * @throws IOException          if the built-in resource location could not be loaded,
 *                              or if {code}allowMissing{code} is false and any custom resource location
 *                              fails to load
 * @throws NullPointerException if any resource location is null
 */
public static PropertyResolver newMultiResourcePropertyResolver(boolean allowMissing,
    String builtInResourceLocation,
    String... customResourceLocations)
    throws IOException {
  MutablePropertySources sources = new MutablePropertySources();
  checkNotNull(builtInResourceLocation, "builtInResourceLocation is null");
  sources.addLast(buildPropertySource(BUILT_IN_NAME, builtInResourceLocation,
      false));
  String lastname = BUILT_IN_NAME;
  int customCtr = 1;
  for (String loc : customResourceLocations) {
    checkNotNull(loc, "customResourceLocations[" + (customCtr - 1) +
        "] is null");
    String thisname = CUSTOM_NAME_PREFIX + customCtr++;
    PropertySource source = buildPropertySource(thisname, loc, allowMissing);
    if (source != null) {
      sources.addBefore(lastname, source);
      lastname = thisname;
    }
  }

  return new PropertySourcesPropertyResolver(sources);
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:41,代码来源:PropertyResolvers.java

示例4: processNonEnumerablePropertySource

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private void processNonEnumerablePropertySource(PropertySource<?> source,
		PropertySourcesPropertyResolver resolver) {
	// We can only do exact matches for non-enumerable property names, but
	// that's better than nothing...
	if (this.nonEnumerableFallbackNames == null) {
		return;
	}
	for (String propertyName : this.nonEnumerableFallbackNames) {
		if (!source.containsProperty(propertyName)) {
			continue;
		}
		Object value = null;
		try {
			value = resolver.getProperty(propertyName, Object.class);
		}
		catch (RuntimeException ex) {
			// Probably could not convert to Object, weird, but ignoreable
		}
		if (value == null) {
			value = source.getProperty(propertyName.toUpperCase());
		}
		putIfAbsent(propertyName, value, source);
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:25,代码来源:PropertySourcesPropertyValues.java

示例5: postProcessBeanFactory

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) {
    if (propertySources == null) {
        propertySources = new MutablePropertySources();
        if (environment != null) {
            propertySources.addLast(
                new PropertySource<Environment>(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, environment) {
                    @Override
                    public String getProperty(final String key) {
                        return source.getProperty(key);
                    }
                }
            );
        }
        ConfigPropertySource configPropertySource = new ConfigPropertySource(CONFIG_PROPERTY_SOURCE_NAME, config);
        if (localOverride) {
            propertySources.addFirst(configPropertySource);
        }
        else {
            propertySources.addLast(configPropertySource);
        }
    }
    processProperties(beanFactory, new PropertySourcesPropertyResolver(propertySources));
    appliedPropertySources = propertySources;
}
 
开发者ID:ctzen,项目名称:slurper-configuration,代码行数:26,代码来源:ConfigPlaceholderConfigurer.java

示例6: postProcessBeanFactory

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
 * against this configurer's set of {@link PropertySources}, which includes:
 * <ul>
 * <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
 * environment property sources}, if an {@code Environment} {@linkplain #setEnvironment is present}
 * <li>{@linkplain #mergeProperties merged local properties}, if {@linkplain #setLocation any}
 * {@linkplain #setLocations have} {@linkplain #setProperties been}
 * {@linkplain #setPropertiesArray specified}
 * <li>any property sources set by calling {@link #setPropertySources}
 * </ul>
 * <p>If {@link #setPropertySources} is called, <strong>environment and local properties will be
 * ignored</strong>. This method is designed to give the user fine-grained control over property
 * sources, and once set, the configurer makes no assumptions about adding additional sources.
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	if (this.propertySources == null) {
		this.propertySources = new MutablePropertySources();
		if (this.environment != null) {
			this.propertySources.addLast(
				new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
					@Override
					public String getProperty(String key) {
						return this.source.getProperty(key);
					}
				}
			);
		}
		try {
			PropertySource<?> localPropertySource =
				new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
			if (this.localOverride) {
				this.propertySources.addFirst(localPropertySource);
			}
			else {
				this.propertySources.addLast(localPropertySource);
			}
		}
		catch (IOException ex) {
			throw new BeanInitializationException("Could not load properties", ex);
		}
	}

	processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
	this.appliedPropertySources = this.propertySources;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:PropertySourcesPlaceholderConfigurer.java

示例7: getConfigurationProperties

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
Map<String, Object> getConfigurationProperties() {
    Map<String, Object> props = asMap(sources, prefix, strip);
    PropertySourcesPropertyResolver propertyResolver = new PropertySourcesPropertyResolver(sources);
    resolveProperties(props, propertyResolver, env);

    return props;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:8,代码来源:FactoryState.java

示例8: postProcessBeanFactory

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
 * against this configurer's set of {@link PropertySources}, which includes:
 * <ul>
 * <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
 * environment property sources}, if an {@code Environment} {@linkplain #setEnvironment is present}
 * <li>{@linkplain #mergeProperties merged local properties}, if {@linkplain #setLocation any}
 * {@linkplain #setLocations have} {@linkplain #setProperties been}
 * {@linkplain #setPropertiesArray specified}
 * <li>any property sources set by calling {@link #setPropertySources}
 * </ul>
 * <p>If {@link #setPropertySources} is called, <strong>environment and local properties will be
 * ignored</strong>. This method is designed to give the user fine-grained control over property
 * sources, and once set, the configurer makes no assumptions about adding additional sources.
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	if (this.propertySources == null) {
		this.propertySources = new MutablePropertySources();
		if (this.environment != null) {
			this.propertySources.addLast(
				new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
					@Override
					public String getProperty(String key) {
						return this.source.getProperty(key);
					}
				}
			);
		}
		try {
			PropertySource<?> localPropertySource =
					new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
			if (this.localOverride) {
				this.propertySources.addFirst(localPropertySource);
			}
			else {
				this.propertySources.addLast(localPropertySource);
			}
		}
		catch (IOException ex) {
			throw new BeanInitializationException("Could not load properties", ex);
		}
	}

	processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
	this.appliedPropertySources = this.propertySources;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:49,代码来源:PropertySourcesPlaceholderConfigurer.java

示例9: getTitleResolver

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private PropertyResolver getTitleResolver(Class<?> sourceClass) {
	MutablePropertySources sources = new MutablePropertySources();
	String applicationTitle = getApplicationTitle(sourceClass);
	Map<String, Object> titleMap = Collections.<String, Object>singletonMap(
			"application.title", (applicationTitle == null ? "" : applicationTitle));
	sources.addFirst(new MapPropertySource("title", titleMap));
	return new PropertySourcesPropertyResolver(sources);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:ResourceBanner.java

示例10: PropertySourcesPropertyValues

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
/**
 * Create a new PropertyValues from the given PropertySources.
 * @param propertySources a PropertySources instance
 * @param nonEnumerableFallbackNames the property names to try in lieu of an
 * {@link EnumerablePropertySource}.
 * @param includes the property name patterns to include
 */
PropertySourcesPropertyValues(PropertySources propertySources,
		Collection<String> nonEnumerableFallbackNames,
		PropertyNamePatternsMatcher includes) {
	Assert.notNull(propertySources, "PropertySources must not be null");
	Assert.notNull(includes, "Includes must not be null");
	this.propertySources = propertySources;
	this.nonEnumerableFallbackNames = nonEnumerableFallbackNames;
	this.includes = includes;
	PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(
			propertySources);
	for (PropertySource<?> source : propertySources) {
		processPropertySource(source, resolver);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:PropertySourcesPropertyValues.java

示例11: processPropertySource

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private void processPropertySource(PropertySource<?> source,
		PropertySourcesPropertyResolver resolver) {
	if (source instanceof CompositePropertySource) {
		processCompositePropertySource((CompositePropertySource) source, resolver);
	}
	else if (source instanceof EnumerablePropertySource) {
		processEnumerablePropertySource((EnumerablePropertySource<?>) source,
				resolver, this.includes);
	}
	else {
		processNonEnumerablePropertySource(source, resolver);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:PropertySourcesPropertyValues.java

示例12: processEnumerablePropertySource

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private void processEnumerablePropertySource(EnumerablePropertySource<?> source,
		PropertySourcesPropertyResolver resolver,
		PropertyNamePatternsMatcher includes) {
	if (source.getPropertyNames().length > 0) {
		for (String propertyName : source.getPropertyNames()) {
			if (includes.matches(propertyName)) {
				Object value = getEnumerableProperty(source, resolver, propertyName);
				putIfAbsent(propertyName, value, source);
			}
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:PropertySourcesPropertyValues.java

示例13: getEnumerableProperty

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private Object getEnumerableProperty(EnumerablePropertySource<?> source,
		PropertySourcesPropertyResolver resolver, String propertyName) {
	try {
		return resolver.getProperty(propertyName, Object.class);
	}
	catch (RuntimeException ex) {
		// Probably could not resolve placeholders, ignore it here
		return source.getProperty(propertyName);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:PropertySourcesPropertyValues.java

示例14: getPropertyResolver

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
private PropertyResolver getPropertyResolver(String file, String path) {
	Map<String, Object> properties = new LinkedHashMap<String, Object>();
	properties.put("logging.file", file);
	properties.put("logging.path", path);
	PropertySource<?> propertySource = new MapPropertySource("properties",
			properties);
	MutablePropertySources propertySources = new MutablePropertySources();
	propertySources.addFirst(propertySource);
	return new PropertySourcesPropertyResolver(propertySources);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:LogFileTests.java

示例15: postProcessBeanFactory

import org.springframework.core.env.PropertySourcesPropertyResolver; //导入依赖的package包/类
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	if (this.propertySources == null) {
		this.propertySources = new MutablePropertySources();
		if (this.environment != null) {
			this.propertySources.addLast(
					new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
						@Override
						public String getProperty(String key) {
							return this.source.getProperty(key);
						}
					});
		}
		PropertySource<?> localPropertySource = new PropertySource<Configuration>(
				PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, configuration) {
			@Override
			public Object getProperty(String name) {
				if (name != null && name.indexOf("?:") > 0) {
					name = name.substring(0, name.indexOf("?:"));
				}
				return this.source.getProperty(name);
			}
		};
		propertySources.addFirst(localPropertySource);
	}

	processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
	this.appliedPropertySources = this.propertySources;
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:30,代码来源:ConfigurationPropertySourcesPlaceholderConfigurer.java


注:本文中的org.springframework.core.env.PropertySourcesPropertyResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。