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

Closes gh-3044
This commit is contained in:
Stephane Nicoll
2016-04-26 08:59:41 +02:00
parent 5f41e82a89
commit 1ef3327441
6 changed files with 26 additions and 36 deletions

View File

@@ -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 {

View File

@@ -1,5 +1,5 @@
/*
* 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.

View File

@@ -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",

View File

@@ -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();