@ -16,6 +16,7 @@
@@ -16,6 +16,7 @@
package org.springframework.boot.context.properties ;
import java.time.Duration ;
import java.util.Collections ;
import java.util.HashMap ;
import java.util.LinkedHashMap ;
@ -458,6 +459,19 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
@@ -458,6 +459,19 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
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 ) {
try {
this . context . refresh ( ) ;
@ -970,6 +984,23 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
@@ -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
@EnableConfigurationProperties ( PropertyWithoutConfigurationPropertiesAnnotation . class )
public static class ConfigurationPropertiesWithoutAnnotation {