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;
@Configuration
@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class,
MultipartConfigElement.class })
@ConditionalOnProperty(prefix = "multipart", name = "enabled", matchIfMissing = true)
@ConditionalOnProperty(prefix = "spring.http.multipart", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(MultipartProperties.class)
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");
* you may not use this file except in compliance with the License.
......@@ -25,16 +25,16 @@ import org.springframework.util.StringUtils;
/**
* Properties to be used in configuring a {@link MultipartConfigElement}.
* <ul>
* <li>{@literal multipart.location} specifies the directory where files will be stored.
* The default is "". A common value is to use the system's temporary directory, which can
* be obtained.</li>
* <li>{@literal multipart.maxFileSize} specifies the maximum size permitted for uploaded
* files. The default is 1Mb.</li>
* <li>{@literal multipart.maxRequestSize} specifies the maximum size allowed for
* {@literal multipart/form-data} requests. The default is 10Mb</li>
* <li>{@literal multipart.fileSizeThreshold} specifies the size threshold after which
* files will be written to disk. Default is 0, which means that the file will be written
* to disk immediately.</li>
* <li>{@link #getLocation() location} specifies the directory where files will be
* stored. The default is "". A common value is to use the system's temporary directory,
* which can be obtained.</li>
* <li>{@link #getMaxFileSize() max-file-size} specifies the maximum size permitted for
* uploaded files. The default is 1Mb.</li>
* <li>{@link #getMaxRequestSize() max-request-size} specifies the maximum size allowed
* for {@literal multipart/form-data} requests. The default is 10Mb</li>
* <li>{@link #getFileSizeThreshold() file-size-threshold} specifies the size threshold
* after which files will be written to disk. Default is 0, which means that the file
* will be written to disk immediately.</li>
* </ul>
* <p>
* These properties are ultimately passed through
......@@ -45,13 +45,13 @@ import org.springframework.util.StringUtils;
* @author Josh Long
* @since 1.1.0
*/
@ConfigurationProperties(prefix = "multipart", ignoreUnknownFields = false)
@ConfigurationProperties(prefix = "spring.http.multipart", ignoreUnknownFields = false)
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.
......
......@@ -7,12 +7,6 @@
"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",
"type": "java.lang.Boolean",
......
......@@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.web;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.MultipartConfigElement;
......@@ -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.undertow.UndertowEmbeddedServletContainerFactory;
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.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.MapPropertySource;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest;
......@@ -170,10 +168,8 @@ public class MultipartAutoConfigurationTests {
private void testContainerWithCustomMultipartConfigEnabledSetting(
final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put("multipart.enabled", propertyValue);
MapPropertySource propertySource = new MapPropertySource("test", properties);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.http.multipart.enabled=" + propertyValue);
this.context.register(ContainerWithNoMultipartTomcat.class,
BaseConfiguration.class);
this.context.refresh();
......
......@@ -143,13 +143,6 @@ content into your application; rather pick only the properties that you need.
# 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])
server.address= # Network address to which the server should bind to.
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.
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.
# 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])
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.
......
......@@ -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`
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 `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
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