Spring Boot ClassNotFoundException when configuring maxUploadSize of CommonMultipartResolver
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If CommonMultipartResolver or Apache Commons FileUpload classes are missing when you try to set maxUploadSize, you are usually mixing old Spring MVC examples with modern Spring Boot configuration. In current Spring Boot applications, the normal fix is to stop configuring the Commons resolver and use Boot's built-in multipart support instead.
Why the Exception Happens
Older tutorials often show a bean like CommonsMultipartResolver and then call setMaxUploadSize(...). That worked in older Spring MVC setups that depended on Apache Commons FileUpload. In a typical Spring Boot application, however, multipart handling is auto-configured around the servlet Part API.
So this pattern often fails:
The failure means one of two things:
- the Apache Commons FileUpload classes are not on the classpath
- you are following an outdated approach for the Spring Boot version you are using
In modern Spring Framework releases, StandardServletMultipartResolver is the main supported resolver. That is why current Boot documentation points you toward configuration properties instead of a custom Commons bean.
Recommended Fix in Spring Boot
For most projects, remove the custom multipart resolver bean and configure limits in properties or YAML.
Then your controller can stay simple:
This is the approach that best matches how Spring Boot auto-configuration works. You do not need CommonsMultipartResolver just to set upload size limits.
What to Do in Legacy Applications
If you are maintaining an older application that truly depends on Apache Commons FileUpload, then you need the matching dependency and configuration style for that older stack.
For Maven, that might look like:
And then the legacy bean becomes valid:
That is a compatibility path, not the default recommendation for a new Boot application.
Handling Upload Errors Cleanly
Whichever resolver strategy you use, you should translate upload-size failures into a clear response. Otherwise users see an unhelpful server error.
That does not solve the ClassNotFoundException, but it completes the upload flow once the resolver is configured correctly.
How to Decide Which Path You Are On
Ask two simple questions:
- Am I building a current Spring Boot application?
- Do I actually need Apache Commons FileUpload-specific behavior?
If the answer to the first is yes and the second is no, use spring.servlet.multipart.* properties and remove the custom resolver bean.
If the codebase is older and already built around Commons FileUpload, then keep that path but make sure the dependency matches the framework version and the bean name is multipartResolver.
Common Pitfalls
The most common mistake is copying a pre-Boot or old Boot example into a modern application and assuming multipart configuration still works the same way.
Another mistake is adding a custom resolver bean without understanding that Boot already auto-configures multipart support. That can create confusion even when it does not throw immediately.
People also forget that file-size properties and bean-based byte limits are different styles. Mixing them without a clear reason makes the application harder to maintain.
Finally, if you are on a recent Spring stack, be careful with old imports and examples that rely on classes no longer present in the current framework line.
Summary
- '
ClassNotFoundExceptionhere usually means an outdated multipart configuration approach.' - In modern Spring Boot, prefer
spring.servlet.multipart.max-file-sizeandmax-request-size. - Use
MultipartFilewith Boot's built-in multipart support instead of forcingCommonsMultipartResolver. - Only add Apache Commons FileUpload for legacy applications that explicitly depend on it.
- Handle oversized uploads with an exception handler so the runtime behavior stays clear.
Related reading
- Spring Boot classpath
- Spring Boot Cloud Zuul Proxy 404 Error
- Spring boot config server
- Spring Boot Configuration Class is simply ignored and not loaded
- Spring Boot configure and use two data sources
- Spring Boot configure and use two data sources
- Spring boot Configure your tomcat server to work with html5Mode
- Spring Boot containers can not connect to the Kafka container

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.