Commit 1ef33274 authored by Stephane Nicoll's avatar Stephane Nicoll

Move multipart.* properties to spring.http.multipart.*

Closes gh-3044
parent 5f41e82a
...@@ -47,7 +47,7 @@ import org.springframework.web.servlet.DispatcherServlet; ...@@ -47,7 +47,7 @@ import org.springframework.web.servlet.DispatcherServlet;
@Configuration @Configuration
@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class, @ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class,
MultipartConfigElement.class }) MultipartConfigElement.class })
@ConditionalOnProperty(prefix = "multipart", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.http.multipart", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(MultipartProperties.class) @EnableConfigurationProperties(MultipartProperties.class)
public class MultipartAutoConfiguration { public class MultipartAutoConfiguration {
......
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -25,16 +25,16 @@ import org.springframework.util.StringUtils; ...@@ -25,16 +25,16 @@ import org.springframework.util.StringUtils;
/** /**
* Properties to be used in configuring a {@link MultipartConfigElement}. * Properties to be used in configuring a {@link MultipartConfigElement}.
* <ul> * <ul>
* <li>{@literal multipart.location} specifies the directory where files will be stored. * <li>{@link #getLocation() location} specifies the directory where files will be
* The default is "". A common value is to use the system's temporary directory, which can * stored. The default is "". A common value is to use the system's temporary directory,
* be obtained.</li> * which can be obtained.</li>
* <li>{@literal multipart.maxFileSize} specifies the maximum size permitted for uploaded * <li>{@link #getMaxFileSize() max-file-size} specifies the maximum size permitted for
* files. The default is 1Mb.</li> * uploaded files. The default is 1Mb.</li>
* <li>{@literal multipart.maxRequestSize} specifies the maximum size allowed for * <li>{@link #getMaxRequestSize() max-request-size} specifies the maximum size allowed
* {@literal multipart/form-data} requests. The default is 10Mb</li> * for {@literal multipart/form-data} requests. The default is 10Mb</li>
* <li>{@literal multipart.fileSizeThreshold} specifies the size threshold after which * <li>{@link #getFileSizeThreshold() file-size-threshold} specifies the size threshold
* files will be written to disk. Default is 0, which means that the file will be written * after which files will be written to disk. Default is 0, which means that the file
* to disk immediately.</li> * will be written to disk immediately.</li>
* </ul> * </ul>
* <p> * <p>
* These properties are ultimately passed through * These properties are ultimately passed through
...@@ -45,13 +45,13 @@ import org.springframework.util.StringUtils; ...@@ -45,13 +45,13 @@ import org.springframework.util.StringUtils;
* @author Josh Long * @author Josh Long
* @since 1.1.0 * @since 1.1.0
*/ */
@ConfigurationProperties(prefix = "multipart", ignoreUnknownFields = false) @ConfigurationProperties(prefix = "spring.http.multipart", ignoreUnknownFields = false)
public class MultipartProperties { public class MultipartProperties {
/** /**
* Enable multipart upload handling. * Enable support of multi-part uploads.
*/ */
private boolean enabled; private boolean enabled = true;
/** /**
* Intermediate location of uploaded files. * Intermediate location of uploaded files.
......
...@@ -7,12 +7,6 @@ ...@@ -7,12 +7,6 @@
"replacement": "server.error.path" "replacement": "server.error.path"
} }
}, },
{
"name": "multipart.enabled",
"type": "java.lang.Boolean",
"description": "Enable support of multi-part uploads.",
"defaultValue": true
},
{ {
"name": "server.error.whitelabel.enabled", "name": "server.error.whitelabel.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.web; package org.springframework.boot.autoconfigure.web;
import java.net.URI; import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.MultipartConfigElement; import javax.servlet.MultipartConfigElement;
...@@ -32,10 +30,10 @@ import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletConta ...@@ -32,10 +30,10 @@ import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletConta
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.env.MapPropertySource;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequest;
...@@ -170,10 +168,8 @@ public class MultipartAutoConfigurationTests { ...@@ -170,10 +168,8 @@ public class MultipartAutoConfigurationTests {
private void testContainerWithCustomMultipartConfigEnabledSetting( private void testContainerWithCustomMultipartConfigEnabledSetting(
final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) { final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context = new AnnotationConfigEmbeddedWebApplicationContext();
Map<String, Object> properties = new LinkedHashMap<String, Object>(); EnvironmentTestUtils.addEnvironment(this.context,
properties.put("multipart.enabled", propertyValue); "spring.http.multipart.enabled=" + propertyValue);
MapPropertySource propertySource = new MapPropertySource("test", properties);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(ContainerWithNoMultipartTomcat.class, this.context.register(ContainerWithNoMultipartTomcat.class,
BaseConfiguration.class); BaseConfiguration.class);
this.context.refresh(); this.context.refresh();
......
...@@ -143,13 +143,6 @@ content into your application; rather pick only the properties that you need. ...@@ -143,13 +143,6 @@ content into your application; rather pick only the properties that you need.
# WEB PROPERTIES # WEB PROPERTIES
# ---------------------------------------- # ----------------------------------------
# MULTIPART ({sc-spring-boot-autoconfigure}/web/MultipartProperties.{sc-ext}[MultipartProperties])
multipart.enabled=true # Enable support of multi-part uploads.
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.
multipart.location= # Intermediate location of uploaded files.
multipart.max-file-size=1Mb # Max file size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size.
multipart.max-request-size=10Mb # Max request size. Values can use the suffixed "MB" or "KB" to indicate a Megabyte or Kilobyte size.
# EMBEDDED SERVER CONFIGURATION ({sc-spring-boot-autoconfigure}/web/ServerProperties.{sc-ext}[ServerProperties]) # EMBEDDED SERVER CONFIGURATION ({sc-spring-boot-autoconfigure}/web/ServerProperties.{sc-ext}[ServerProperties])
server.address= # Network address to which the server should bind to. server.address= # Network address to which the server should bind to.
server.compression.enabled=false # If response compression is enabled. server.compression.enabled=false # If response compression is enabled.
...@@ -277,6 +270,13 @@ content into your application; rather pick only the properties that you need. ...@@ -277,6 +270,13 @@ content into your application; rather pick only the properties that you need.
spring.http.encoding.enabled=true # Enable http encoding support. spring.http.encoding.enabled=true # Enable http encoding support.
spring.http.encoding.force=true # Force the encoding to the configured charset on HTTP requests and responses. spring.http.encoding.force=true # Force the encoding to the configured charset on HTTP requests and responses.
# MULTIPART ({sc-spring-boot-autoconfigure}/web/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.
# JACKSON ({sc-spring-boot-autoconfigure}/jackson/JacksonProperties.{sc-ext}[JacksonProperties]) # 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`. spring.jackson.date-format= # Date format string or a fully-qualified date format class name. For instance `yyyy-MM-dd HH:mm:ss`.
spring.jackson.default-property-inclusion= # Controls the inclusion of properties during serialization. spring.jackson.default-property-inclusion= # Controls the inclusion of properties during serialization.
......
...@@ -1211,7 +1211,7 @@ file and a maximum of 10Mb of file data in a single request. You may override th ...@@ -1211,7 +1211,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` 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 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 exposed in the `MultipartProperties` class. If you want to specify that files be
unlimited, for example, set the `multipart.maxFileSize` property to `-1`. unlimited, for example, set the `spring.http.multipart.max-file-size` property to `-1`.
The multipart support is helpful when you want to receive multipart encoded file data as 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 a `@RequestParam`-annotated parameter of type `MultipartFile` in a Spring MVC controller
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment