diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java index 4e53b99830d..1084a1fd67e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java @@ -45,6 +45,7 @@ class DurationConverter implements GenericConverter { static { Set types = new LinkedHashSet<>(); types.add(new ConvertiblePair(String.class, Duration.class)); + types.add(new ConvertiblePair(Integer.class, Duration.class)); TYPES = Collections.unmodifiableSet(types); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/convert/BinderConversionServiceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/convert/BinderConversionServiceTests.java index d850ade1f8a..a785ce88eb1 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/convert/BinderConversionServiceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/convert/BinderConversionServiceTests.java @@ -161,6 +161,13 @@ public class BinderConversionServiceTests { assertThat(converted).isEqualTo(Duration.ofSeconds(10)); } + @Test + public void conversionServiceShouldSupportIntegerToDuration() throws Exception { + this.service = new BinderConversionService(null); + Duration converted = this.service.convert(10, Duration.class); + assertThat(converted).isEqualTo(Duration.ofMillis(10)); + } + enum TestEnum { ONE, TWO