|
28 | 28 | import org.springframework.boot.context.properties.ConfigurationProperties;
|
29 | 29 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
30 | 30 | import org.springframework.boot.diagnostics.FailureAnalysis;
|
| 31 | +import org.springframework.boot.logging.LogLevel; |
31 | 32 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
32 | 33 | import org.springframework.core.env.MapPropertySource;
|
33 | 34 | import org.springframework.core.env.MutablePropertySources;
|
@@ -88,6 +89,16 @@ void bindExceptionDueToClassNotFoundConvertionFailure() {
|
88 | 89 | "failed to convert java.lang.String to java.lang.Class<?> (caused by java.lang.ClassNotFoundException: com.example.Missing"));
|
89 | 90 | }
|
90 | 91 |
|
| 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 | + |
91 | 102 | private static String failure(String property, String value, String origin, String reason) {
|
92 | 103 | return String.format("Property: %s%n Value: %s%n Origin: %s%n Reason: %s", property, value, origin,
|
93 | 104 | reason);
|
@@ -150,6 +161,11 @@ static class NestedFailureConfiguration {
|
150 | 161 |
|
151 | 162 | }
|
152 | 163 |
|
| 164 | + @EnableConfigurationProperties(LoggingProperties.class) |
| 165 | + static class LoggingLevelFailureConfiguration { |
| 166 | + |
| 167 | + } |
| 168 | + |
153 | 169 | @ConfigurationProperties("test.foo")
|
154 | 170 | @Validated
|
155 | 171 | static class FieldValidationFailureProperties {
|
@@ -237,6 +253,21 @@ void setValue(String value) {
|
237 | 253 |
|
238 | 254 | }
|
239 | 255 |
|
| 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 | + |
240 | 271 | enum Fruit {
|
241 | 272 |
|
242 | 273 | APPLE, BANANA, ORANGE
|
|
0 commit comments