|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2021 the original author or authors. |
| 2 | + * Copyright 2012-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
29 | 29 | import org.springframework.boot.context.properties.ConfigurationProperties;
|
30 | 30 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
31 | 31 | import org.springframework.boot.diagnostics.FailureAnalysis;
|
| 32 | +import org.springframework.boot.logging.LogLevel; |
32 | 33 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
33 | 34 | import org.springframework.core.env.MapPropertySource;
|
34 | 35 | import org.springframework.core.env.MutablePropertySources;
|
@@ -89,6 +90,16 @@ void bindExceptionDueToClassNotFoundConvertionFailure() {
|
89 | 90 | "failed to convert java.lang.String to java.lang.Class<?> (caused by java.lang.ClassNotFoundException: com.example.Missing"));
|
90 | 91 | }
|
91 | 92 |
|
| 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 | + |
92 | 103 | private static String failure(String property, String value, String origin, String reason) {
|
93 | 104 | return String.format("Property: %s%n Value: %s%n Origin: %s%n Reason: %s", property, value, origin,
|
94 | 105 | reason);
|
@@ -151,6 +162,11 @@ static class NestedFailureConfiguration {
|
151 | 162 |
|
152 | 163 | }
|
153 | 164 |
|
| 165 | + @EnableConfigurationProperties(LoggingProperties.class) |
| 166 | + static class LoggingLevelFailureConfiguration { |
| 167 | + |
| 168 | + } |
| 169 | + |
154 | 170 | @ConfigurationProperties("test.foo")
|
155 | 171 | @Validated
|
156 | 172 | static class FieldValidationFailureProperties {
|
@@ -238,6 +254,21 @@ void setValue(String value) {
|
238 | 254 |
|
239 | 255 | }
|
240 | 256 |
|
| 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 | + |
241 | 272 | enum Fruit {
|
242 | 273 |
|
243 | 274 | APPLE, BANANA, ORANGE
|
|
0 commit comments