Skip to content

Commit 3987dec

Browse files
committed
Merge branch '2.7.x'
2 parents afdb651 + 3c5cea4 commit 3987dec

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.boot.context.properties.ConfigurationProperties;
2929
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3030
import org.springframework.boot.diagnostics.FailureAnalysis;
31+
import org.springframework.boot.logging.LogLevel;
3132
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3233
import org.springframework.core.env.MapPropertySource;
3334
import org.springframework.core.env.MutablePropertySources;
@@ -88,6 +89,16 @@ void bindExceptionDueToClassNotFoundConvertionFailure() {
8889
"failed to convert java.lang.String to java.lang.Class<?> (caused by java.lang.ClassNotFoundException: com.example.Missing"));
8990
}
9091

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

151162
}
152163

164+
@EnableConfigurationProperties(LoggingProperties.class)
165+
static class LoggingLevelFailureConfiguration {
166+
167+
}
168+
153169
@ConfigurationProperties("test.foo")
154170
@Validated
155171
static class FieldValidationFailureProperties {
@@ -237,6 +253,21 @@ void setValue(String value) {
237253

238254
}
239255

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

242273
APPLE, BANANA, ORANGE

0 commit comments

Comments
 (0)