Skip to content

Commit 3f23c08

Browse files
committed
Merge branch '2.5.x' into 2.6.x
Closes gh-30788
2 parents 5c3be7c + ce78865 commit 3f23c08

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,6 +61,7 @@ protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> targe
6161
if (!ConfigurationPropertyName.EMPTY.equals(name)) {
6262
ConfigurationProperty property = source.getConfigurationProperty(name);
6363
if (property != null && !hasDescendants) {
64+
getContext().setConfigurationProperty(property);
6465
return getContext().getConverter().convert(property.getValue(), target);
6566
}
6667
source = source.filter(name::isAncestorOf);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BindFailureAnalyzerTests.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
import org.springframework.boot.context.properties.ConfigurationProperties;
3030
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3131
import org.springframework.boot.diagnostics.FailureAnalysis;
32+
import org.springframework.boot.logging.LogLevel;
3233
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3334
import org.springframework.core.env.MapPropertySource;
3435
import org.springframework.core.env.MutablePropertySources;
@@ -89,6 +90,16 @@ void bindExceptionDueToClassNotFoundConvertionFailure() {
8990
"failed to convert java.lang.String to java.lang.Class<?> (caused by java.lang.ClassNotFoundException: com.example.Missing"));
9091
}
9192

93+
@Test
94+
void bindExceptionDueToMapConversionFailure() {
95+
FailureAnalysis analysis = performAnalysis(LoggingLevelFailureConfiguration.class, "logging.level=debug");
96+
assertThat(analysis.getDescription()).contains(failure("logging.level", "debug",
97+
"\"logging.level\" from property source \"test\"",
98+
"org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting "
99+
+ "from type [java.lang.String] to type [java.util.Map<java.lang.String, "
100+
+ "org.springframework.boot.logging.LogLevel>]"));
101+
}
102+
92103
private static String failure(String property, String value, String origin, String reason) {
93104
return String.format("Property: %s%n Value: %s%n Origin: %s%n Reason: %s", property, value, origin,
94105
reason);
@@ -151,6 +162,11 @@ static class NestedFailureConfiguration {
151162

152163
}
153164

165+
@EnableConfigurationProperties(LoggingProperties.class)
166+
static class LoggingLevelFailureConfiguration {
167+
168+
}
169+
154170
@ConfigurationProperties("test.foo")
155171
@Validated
156172
static class FieldValidationFailureProperties {
@@ -238,6 +254,21 @@ void setValue(String value) {
238254

239255
}
240256

257+
@ConfigurationProperties("logging")
258+
static class LoggingProperties {
259+
260+
private Map<String, LogLevel> level = new HashMap<>();
261+
262+
Map<String, LogLevel> getLevel() {
263+
return this.level;
264+
}
265+
266+
void setLevel(Map<String, LogLevel> level) {
267+
this.level = level;
268+
}
269+
270+
}
271+
241272
enum Fruit {
242273

243274
APPLE, BANANA, ORANGE

0 commit comments

Comments
 (0)