Spring MVC file upload – Unable to process parts as no multi-part configuration has been provided

When you implement file upload in a Spring MVC application, sometimes you may encounter an error message like Unable to process parts as no multi-part configuration has been provided. This is because your servlet is version 3.0 or newer and tomcat needs you to set multipart configure settings to the servlet instance. This article will tell you how to do.

1. Set Multipart Config In Code.

If your spring project uses JavaConfig ( not using XML configuration ), then you can set the multipart config to the dispatcher servlet in the configuration servlet onStartup method like below.

import javax.servlet.FilterRegistration;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.multipart.support.MultipartFilter;
import org.springframework.web.servlet.DispatcherServlet;

public class ExampleDispatcherServlet implements WebApplicationInitializer {

      public void onStartup(ServletContext servletContext) throws ServletException {

            AnnotationConfigWebApplicationContext dispatcherServletContext = new AnnotationConfigWebApplicationContext();


            DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherServletContext);

            ServletRegistration.Dynamic dispatcher = servletContext.addServlet("simple-example", dispatcherServlet);

            /* If do not set multipartcofgin in servlet 3, when you upload a file, it will throw Unable to process parts as no multi-part configuration has been provided error. */
            MultipartConfigElement multipartConfig = new MultipartConfigElement("/tmp");



            FilterRegistration.Dynamic multipartFilter = servletContext.addFilter("multipartFilter", MultipartFilter.class);
            multipartFilter.addMappingForUrlPatterns(null, true, "/*");



2. Set Multipart Config In Web.xml.

If you use XML configuration for your spring project, you should add the below XML code in the WEB-INF/web.xml file.


3. Use MultipartConfig Annotation.

public class Dispatcher extends HttpServlet



  1. If your Html form contains enctype=’multipart/form-data’, then your servlet which process file upload must be configured to support multipart configuration.

Subscribe to receive more programming tricks.

We don’t spam!

Subscribe to receive more programming tricks.

We don’t spam!

5 1 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x