diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java index 15e9cc48eb..0ac3326d2c 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletMultipartResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -41,6 +41,18 @@ import org.springframework.web.multipart.MultipartResolver; * storage locations need to be applied at that servlet registration level; * Servlet 3.0 does not allow for them to be set at the MultipartResolver level. * + *
+ * public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
+ *	// ...
+ *	@Override
+ *	protected void customizeRegistration(ServletRegistration.Dynamic registration) {
+ *
+ *		// Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold
+ *		registration.setMultipartConfig(new MultipartConfigElement("/tmp"));
+ *	}
+ * }
+ * 
+ * * @author Juergen Hoeller * @since 3.1 * @see #setResolveLazily diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 7381217989..e41915ca0b 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -999,11 +999,27 @@ have `commons-fileupload` as a dependency on your classpath. [[mvc-multipart-resolver-standard]] ==== Servlet 3.0 -To use Servlet 3.0 multipart support, you need to register the `DispatcherServlet` -accordingly. In programmatic Servlet registration, set a `MultipartConfigElement` on the -Servlet registration. In `web.xml`, add a `""` section. Configuration -settings such as maximum sizes or storage locations need to be applied at this level -since Servlet 3.0 API does not make it possible for the `MultipartResolver` to do so. +Servlet 3.0 multipart parsing needs to be enabled through Servlet container configuration: + +* in Java, set a `MultipartConfigElement` on the Servlet registration. +* in `web.xml`, add a `""` section to the servlet declaration. + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { + + // ... + + @Override + protected void customizeRegistration(ServletRegistration.Dynamic registration) { + + // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold + registration.setMultipartConfig(new MultipartConfigElement("/tmp")); + } + + } +---- Once the Servlet 3.0 configuration is in place, simply add a bean of type `StandardServletMultipartResolver` with the name `multipartResolver`.