Skip to content

Commit c1b1f14

Browse files
committed
Fix default unit for multipart properties
This commit fixes a regression that wrongly changed the default unit of multipart properties from bytes to megabytes. Closes gh-15162
1 parent 2f4325d commit c1b1f14

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
import org.springframework.boot.context.properties.ConfigurationProperties;
2222
import org.springframework.boot.context.properties.PropertyMapper;
23-
import org.springframework.boot.convert.DataSizeUnit;
2423
import org.springframework.boot.web.servlet.MultipartConfigFactory;
2524
import org.springframework.util.unit.DataSize;
26-
import org.springframework.util.unit.DataUnit;
2725

2826
/**
2927
* Properties to be used in configuring a {@link MultipartConfigElement}.
@@ -63,13 +61,11 @@ public class MultipartProperties {
6361
/**
6462
* Max file size.
6563
*/
66-
@DataSizeUnit(DataUnit.MEGABYTES)
6764
private DataSize maxFileSize = DataSize.ofMegabytes(1);
6865

6966
/**
7067
* Max request size.
7168
*/
72-
@DataSizeUnit(DataUnit.MEGABYTES)
7369
private DataSize maxRequestSize = DataSize.ofMegabytes(10);
7470

7571
/**

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,37 @@ public void configureResolveLazily() {
209209
assertThat(multipartResolver).hasFieldOrPropertyWithValue("resolveLazily", true);
210210
}
211211

212+
@Test
213+
public void configureMultipartProperties() {
214+
this.context = new AnnotationConfigServletWebServerApplicationContext();
215+
TestPropertyValues
216+
.of("spring.servlet.multipart.max-file-size=2048KB",
217+
"spring.servlet.multipart.max-request-size=15MB")
218+
.applyTo(this.context);
219+
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
220+
this.context.refresh();
221+
MultipartConfigElement multipartConfigElement = this.context
222+
.getBean(MultipartConfigElement.class);
223+
assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(2048 * 1024);
224+
assertThat(multipartConfigElement.getMaxRequestSize())
225+
.isEqualTo(15 * 1024 * 1024);
226+
}
227+
228+
@Test
229+
public void configureMultipartPropertiesWithRawLongValues() {
230+
this.context = new AnnotationConfigServletWebServerApplicationContext();
231+
TestPropertyValues
232+
.of("spring.servlet.multipart.max-file-size=512",
233+
"spring.servlet.multipart.max-request-size=2048")
234+
.applyTo(this.context);
235+
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
236+
this.context.refresh();
237+
MultipartConfigElement multipartConfigElement = this.context
238+
.getBean(MultipartConfigElement.class);
239+
assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(512);
240+
assertThat(multipartConfigElement.getMaxRequestSize()).isEqualTo(2048);
241+
}
242+
212243
private void verify404() throws Exception {
213244
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
214245
ClientHttpRequest request = requestFactory.createRequest(new URI(

0 commit comments

Comments
 (0)