|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.context.properties;
|
|
|
|
package org.springframework.boot.context.properties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
@ -458,6 +459,19 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
|
|
|
|
assertThat(second.getTwo()).isEqualTo("baz");
|
|
|
|
assertThat(second.getTwo()).isEqualTo("baz");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void javaTimeDurationCanBeBound() throws Exception {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
MutablePropertySources sources = this.context.getEnvironment()
|
|
|
|
|
|
|
|
.getPropertySources();
|
|
|
|
|
|
|
|
sources.addFirst(new MapPropertySource("test",
|
|
|
|
|
|
|
|
Collections.singletonMap("test.duration", "PT1M")));
|
|
|
|
|
|
|
|
this.context.register(DurationProperty.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
Duration duration = this.context.getBean(DurationProperty.class).getDuration();
|
|
|
|
|
|
|
|
assertThat(duration.getSeconds()).isEqualTo(60);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void assertBindingFailure(int errorCount) {
|
|
|
|
private void assertBindingFailure(int errorCount) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
@ -970,6 +984,23 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
@EnableConfigurationProperties
|
|
|
|
|
|
|
|
@ConfigurationProperties(prefix = "test")
|
|
|
|
|
|
|
|
public static class DurationProperty {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Duration duration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Duration getDuration() {
|
|
|
|
|
|
|
|
return this.duration;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setDuration(Duration duration) {
|
|
|
|
|
|
|
|
this.duration = duration;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@EnableConfigurationProperties(PropertyWithoutConfigurationPropertiesAnnotation.class)
|
|
|
|
@EnableConfigurationProperties(PropertyWithoutConfigurationPropertiesAnnotation.class)
|
|
|
|
public static class ConfigurationPropertiesWithoutAnnotation {
|
|
|
|
public static class ConfigurationPropertiesWithoutAnnotation {
|
|
|
|