Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-30789
  • Loading branch information
wilkinsona committed Apr 25, 2022
2 parents 25909d0 + 3f23c08 commit 3c5cea4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,6 +61,7 @@ protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> targe
if (!ConfigurationPropertyName.EMPTY.equals(name)) {
ConfigurationProperty property = source.getConfigurationProperty(name);
if (property != null && !hasDescendants) {
getContext().setConfigurationProperty(property);
return getContext().getConverter().convert(property.getValue(), target);
}
source = source.filter(name::isAncestorOf);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.logging.LogLevel;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
Expand Down Expand Up @@ -89,6 +90,16 @@ void bindExceptionDueToClassNotFoundConvertionFailure() {
"failed to convert java.lang.String to java.lang.Class<?> (caused by java.lang.ClassNotFoundException: com.example.Missing"));
}

@Test
void bindExceptionDueToMapConversionFailure() {
FailureAnalysis analysis = performAnalysis(LoggingLevelFailureConfiguration.class, "logging.level=debug");
assertThat(analysis.getDescription()).contains(failure("logging.level", "debug",
"\"logging.level\" from property source \"test\"",
"org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting "
+ "from type [java.lang.String] to type [java.util.Map<java.lang.String, "
+ "org.springframework.boot.logging.LogLevel>]"));
}

private static String failure(String property, String value, String origin, String reason) {
return String.format("Property: %s%n Value: %s%n Origin: %s%n Reason: %s", property, value, origin,
reason);
Expand Down Expand Up @@ -151,6 +162,11 @@ static class NestedFailureConfiguration {

}

@EnableConfigurationProperties(LoggingProperties.class)
static class LoggingLevelFailureConfiguration {

}

@ConfigurationProperties("test.foo")
@Validated
static class FieldValidationFailureProperties {
Expand Down Expand Up @@ -238,6 +254,21 @@ void setValue(String value) {

}

@ConfigurationProperties("logging")
static class LoggingProperties {

private Map<String, LogLevel> level = new HashMap<>();

Map<String, LogLevel> getLevel() {
return this.level;
}

void setLevel(Map<String, LogLevel> level) {
this.level = level;
}

}

enum Fruit {

APPLE, BANANA, ORANGE
Expand Down

0 comments on commit 3c5cea4

Please sign in to comment.