diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java index aa50aafb3b..68dd7af8cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java @@ -20,10 +20,8 @@ import javax.servlet.MultipartConfigElement; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.PropertyMapper; -import org.springframework.boot.convert.DataSizeUnit; import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.util.unit.DataSize; -import org.springframework.util.unit.DataUnit; /** * Properties to be used in configuring a {@link MultipartConfigElement}. @@ -63,13 +61,11 @@ public class MultipartProperties { /** * Max file size. */ - @DataSizeUnit(DataUnit.MEGABYTES) private DataSize maxFileSize = DataSize.ofMegabytes(1); /** * Max request size. */ - @DataSizeUnit(DataUnit.MEGABYTES) private DataSize maxRequestSize = DataSize.ofMegabytes(10); /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java index e5129b9938..d6e15333fc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java @@ -209,6 +209,37 @@ public class MultipartAutoConfigurationTests { assertThat(multipartResolver).hasFieldOrPropertyWithValue("resolveLazily", true); } + @Test + public void configureMultipartProperties() { + this.context = new AnnotationConfigServletWebServerApplicationContext(); + TestPropertyValues + .of("spring.servlet.multipart.max-file-size=2048KB", + "spring.servlet.multipart.max-request-size=15MB") + .applyTo(this.context); + this.context.register(WebServerWithNothing.class, BaseConfiguration.class); + this.context.refresh(); + MultipartConfigElement multipartConfigElement = this.context + .getBean(MultipartConfigElement.class); + assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(2048 * 1024); + assertThat(multipartConfigElement.getMaxRequestSize()) + .isEqualTo(15 * 1024 * 1024); + } + + @Test + public void configureMultipartPropertiesWithRawLongValues() { + this.context = new AnnotationConfigServletWebServerApplicationContext(); + TestPropertyValues + .of("spring.servlet.multipart.max-file-size=512", + "spring.servlet.multipart.max-request-size=2048") + .applyTo(this.context); + this.context.register(WebServerWithNothing.class, BaseConfiguration.class); + this.context.refresh(); + MultipartConfigElement multipartConfigElement = this.context + .getBean(MultipartConfigElement.class); + assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(512); + assertThat(multipartConfigElement.getMaxRequestSize()).isEqualTo(2048); + } + private void verify404() throws Exception { HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); ClientHttpRequest request = requestFactory.createRequest(new URI(