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
This commit is contained in:
@@ -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);
|
||||
|
||||
/**
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user