use of org.springframework.boot.context.properties.source.ConfigurationProperty 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.ConfigurationProperty in project spring-boot by spring-projects.
the class UnboundConfigurationPropertyFailureAnalyzer method analyzeUnboundConfigurationPropertiesException.
private FailureAnalysis analyzeUnboundConfigurationPropertiesException(BindException cause, UnboundConfigurationPropertiesException exception) {
StringBuilder description = new StringBuilder(String.format("Binding to target %s failed:%n", cause.getTarget()));
for (ConfigurationProperty property : exception.getUnboundProperties()) {
buildDescription(description, property);
description.append(String.format("%n Reason: %s", exception.getMessage()));
}
return getFailureAnalysis(description, cause);
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayWhenNonSequentialShouldThrowException.
@Test
void bindToArrayWhenNonSequentialShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0]", "2");
source.put("foo[1]", "1");
source.put("foo[3]", "3");
this.sources.add(source);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", INTEGER_ARRAY)).satisfies((ex) -> {
Set<ConfigurationProperty> unbound = ((UnboundConfigurationPropertiesException) ex.getCause()).getUnboundProperties();
assertThat(unbound.size()).isEqualTo(1);
ConfigurationProperty property = unbound.iterator().next();
assertThat(property.getName().toString()).isEqualTo("foo[3]");
assertThat(property.getValue()).isEqualTo("3");
});
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToNonScalarCollectionWhenNonSequentialShouldThrowException.
@Test
void bindToNonScalarCollectionWhenNonSequentialShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0].value", "1");
source.put("foo[1].value", "2");
source.put("foo[4].value", "4");
this.sources.add(source);
Bindable<List<JavaBean>> target = Bindable.listOf(JavaBean.class);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", target)).satisfies((ex) -> {
Set<ConfigurationProperty> unbound = ((UnboundConfigurationPropertiesException) ex.getCause()).getUnboundProperties();
assertThat(unbound).hasSize(1);
ConfigurationProperty property = unbound.iterator().next();
assertThat(property.getName().toString()).isEqualTo("foo[4].value");
assertThat(property.getValue()).isEqualTo("4");
});
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class IndexedElementsBinder method bindIndexed.
private void bindIndexed(ConfigurationPropertySource source, ConfigurationPropertyName root, Bindable<?> target, AggregateElementBinder elementBinder, IndexedCollectionSupplier collection, ResolvableType aggregateType, ResolvableType elementType) {
ConfigurationProperty property = source.getConfigurationProperty(root);
if (property != null) {
getContext().setConfigurationProperty(property);
bindValue(target, collection.get(), aggregateType, elementType, property.getValue());
} else {
bindIndexed(source, root, elementBinder, collection, elementType);
}
}
Aggregations