From 525f4214419d33e17dd4ad475b5000774f3be7e9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 3 May 2017 15:02:30 +0100 Subject: [PATCH] Update MultipartProperties' prefix to reflect that it's Servlet-specific Closes gh-8628 --- .../servlet/MultipartAutoConfiguration.java | 7 ++++-- .../web/servlet/MultipartProperties.java | 23 +++++++++---------- .../MultipartAutoConfigurationTests.java | 4 ++-- .../appendix-application-properties.adoc | 12 +++++----- spring-boot-docs/src/main/asciidoc/howto.adoc | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java index 71072a688b..1cc9d28474 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java @@ -23,6 +23,8 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; @@ -39,7 +41,7 @@ import org.springframework.web.servlet.DispatcherServlet; * {@link MultipartConfigElement} bean to any {@link Servlet} beans. *

* The {@link javax.servlet.MultipartConfigElement} is a Servlet API that's used to - * configure how the server handles file uploads. By default + * configure how the server handles file uploads. * * @author Greg Turnquist * @author Josh Long @@ -48,7 +50,8 @@ import org.springframework.web.servlet.DispatcherServlet; @Configuration @ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class, MultipartConfigElement.class }) -@ConditionalOnProperty(prefix = "spring.http.multipart", name = "enabled", matchIfMissing = true) +@ConditionalOnProperty(prefix = "spring.servlet.multipart", name = "enabled", matchIfMissing = true) +@ConditionalOnWebApplication(type = Type.SERVLET) @EnableConfigurationProperties(MultipartProperties.class) public class MultipartAutoConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java index 3c64f2df39..4508ea4fd1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartProperties.java @@ -26,15 +26,14 @@ import org.springframework.util.StringUtils; * Properties to be used in configuring a {@link MultipartConfigElement}. *

*

* These properties are ultimately passed through {@link MultipartConfigFactory} which @@ -45,11 +44,11 @@ import org.springframework.util.StringUtils; * @author Toshiaki Maki * @since 1.1.0 */ -@ConfigurationProperties(prefix = "spring.http.multipart", ignoreUnknownFields = false) +@ConfigurationProperties(prefix = "spring.servlet.multipart", ignoreUnknownFields = false) public class MultipartProperties { /** - * Enable support of multi-part uploads. + * Enable support of multipart uploads. */ private boolean enabled = true; @@ -59,20 +58,20 @@ public class MultipartProperties { private String location; /** - * Max file size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or - * Kilobyte size. + * Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or + * kilobytes respectively. */ private String maxFileSize = "1MB"; /** - * Max request size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte - * or Kilobyte size. + * Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or + * kilobytes respectively. */ private String maxRequestSize = "10MB"; /** - * Threshold after which files will be written to disk. Values can use the suffixed - * "MB" or "KB" to indicate a Megabyte or Kilobyte size. + * Threshold after which files will be written to disk. Values can use the suffixes + * "MB" or "KB" to indicate megabytes or kilobytes respectively. */ private String fileSizeThreshold = "0"; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java index 3170187d3a..fdaee9031d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java @@ -183,7 +183,7 @@ public class MultipartAutoConfigurationTests { final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) { this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.http.multipart.enabled=" + propertyValue); + "spring.servlet.multipart.enabled=" + propertyValue); this.context.register(WebServerWithNoMultipartTomcat.class, BaseConfiguration.class); this.context.refresh(); @@ -206,7 +206,7 @@ public class MultipartAutoConfigurationTests { public void configureResolveLazily() { this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.http.multipart.resolve-lazily=true"); + "spring.servlet.multipart.resolve-lazily=true"); this.context.register(WebServerWithNothing.class, BaseConfiguration.class); this.context.refresh(); StandardServletMultipartResolver multipartResolver = this.context diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 0d3c57fac0..f8d490814f 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -303,12 +303,12 @@ content into your application; rather pick only the properties that you need. spring.http.encoding.mapping= # Locale to Encoding mapping. # MULTIPART ({sc-spring-boot-autoconfigure}/web/servlet/MultipartProperties.{sc-ext}[MultipartProperties]) - spring.http.multipart.enabled=true # Enable support of multi-part uploads. - spring.http.multipart.file-size-threshold=0 # Threshold after which files will be written to disk. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size. - spring.http.multipart.location= # Intermediate location of uploaded files. - spring.http.multipart.max-file-size=1MB # Max file size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size. - spring.http.multipart.max-request-size=10MB # Max request size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size. - spring.http.multipart.resolve-lazily=false # Whether to resolve the multipart request lazily at the time of file or parameter access. + spring.servlet.multipart.enabled=true # Enable support of multipart uploads. + spring.servlet.multipart.file-size-threshold=0 # Threshold after which files will be written to disk. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes respectively. + spring.servlet.multipart.location= # Intermediate location of uploaded files. + spring.servlet.multipart.max-file-size=1MB # Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes respectively. + spring.servlet.multipart.max-request-size=10MB # Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes respectively. + spring.servlet.multipart.resolve-lazily=false # Whether to resolve the multipart request lazily at the time of file or parameter access. # JACKSON ({sc-spring-boot-autoconfigure}/jackson/JacksonProperties.{sc-ext}[JacksonProperties]) spring.jackson.date-format= # Date format string or a fully-qualified date format class name. For instance `yyyy-MM-dd HH:mm:ss`. diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 2e9ad17e71..cee4bd9a1a 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1172,7 +1172,7 @@ file and a maximum of 10MB of file data in a single request. You may override th values, as well as the location to which intermediate data is stored (e.g., to the `/tmp` directory) and the threshold past which data is flushed to disk by using the properties exposed in the `MultipartProperties` class. If you want to specify that files be -unlimited, for example, set the `spring.http.multipart.max-file-size` property to `-1`. +unlimited, for example, set the `spring.servlet.multipart.max-file-size` property to `-1`. The multipart support is helpful when you want to receive multipart encoded file data as a `@RequestParam`-annotated parameter of type `MultipartFile` in a Spring MVC controller