use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.
the class ConfigDataEnvironmentContributors method getBinder.
private Binder getBinder(ConfigDataActivationContext activationContext, Predicate<ConfigDataEnvironmentContributor> filter, Set<BinderOption> options) {
boolean failOnInactiveSource = options.contains(BinderOption.FAIL_ON_BIND_TO_INACTIVE_SOURCE);
Iterable<ConfigurationPropertySource> sources = () -> getBinderSources(filter.and((contributor) -> failOnInactiveSource || contributor.isActive(activationContext)));
PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(this.root, activationContext, null, failOnInactiveSource);
BindHandler bindHandler = !failOnInactiveSource ? null : new InactiveSourceChecker(activationContext);
return new Binder(sources, placeholdersResolver, null, null, bindHandler);
}
use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.
the class InactiveConfigDataAccessException method throwIfPropertyFound.
/**
* Throw an {@link InactiveConfigDataAccessException} if the given
* {@link ConfigDataEnvironmentContributor} contains the property.
* @param contributor the contributor to check
* @param name the name to check
*/
static void throwIfPropertyFound(ConfigDataEnvironmentContributor contributor, ConfigurationPropertyName name) {
ConfigurationPropertySource source = contributor.getConfigurationPropertySource();
ConfigurationProperty property = (source != null) ? source.getConfigurationProperty(name) : null;
if (property != null) {
PropertySource<?> propertySource = contributor.getPropertySource();
ConfigDataResource location = contributor.getResource();
throw new InactiveConfigDataAccessException(propertySource, location, name.toString(), property.getOrigin());
}
}
use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.
the class WebMvcPropertiesTests method bind.
private void bind(Map<String, String> map) {
ConfigurationPropertySource source = new MapConfigurationPropertySource(map);
new Binder(source).bind("spring.mvc", Bindable.ofInstance(this.properties));
}
use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.
the class BinderTests method bindWithEmptyPrefixShouldIgnorePropertiesWithEmptyName.
@Test
void bindWithEmptyPrefixShouldIgnorePropertiesWithEmptyName() {
Map<String, Object> source = new HashMap<>();
source.put("value", "hello");
source.put("", "bar");
Iterable<ConfigurationPropertySource> propertySources = ConfigurationPropertySources.from(new MapPropertySource("test", source));
propertySources.forEach(this.sources::add);
Bindable<JavaBean> target = Bindable.of(JavaBean.class);
JavaBean result = this.binder.bind("", target).get();
assertThat(result.getValue()).isEqualTo("hello");
}
use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinder method bindAggregate.
@Override
protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> target, AggregateElementBinder elementBinder) {
Map<Object, Object> map = CollectionFactory.createMap((target.getValue() != null) ? Map.class : target.getType().resolve(Object.class), 0);
Bindable<?> resolvedTarget = resolveTarget(target);
boolean hasDescendants = hasDescendants(name);
for (ConfigurationPropertySource source : getContext().getSources()) {
if (!ConfigurationPropertyName.EMPTY.equals(name)) {
ConfigurationProperty property = source.getConfigurationProperty(name);
if (property != null && !hasDescendants) {
return getContext().getConverter().convert(property.getValue(), target);
}
source = source.filter(name::isAncestorOf);
}
new EntryBinder(name, resolvedTarget, elementBinder).bindEntries(source, map);
}
return map.isEmpty() ? null : map;
}
Aggregations