SpringBoot's MultipartConfig maxFileSize not taking effect
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When Spring Boot file size limits seem to be ignored, the issue is often outside the property you changed. Upload limits can be enforced by Spring multipart settings, servlet container settings, reverse proxies, and custom multipart resolvers. To fix this reliably, verify each layer and test with real upload requests.
Correct Spring Boot Multipart Properties
In modern Spring Boot versions, use the spring.servlet.multipart namespace.
Equivalent YAML:
If property names are wrong for your version, limits may silently stay at defaults.
Verify Controller and Request Mapping
Ensure endpoint actually receives multipart content.
If request is not multipart encoded, multipart limits do not apply as expected.
Conflicts with Custom Multipart Resolver
Custom beans can override auto configuration and bypass property based settings.
If you define a custom resolver, configure limits there too. Otherwise you may think Boot properties are ignored.
Embedded Container Limits and Proxy Limits
Even when Spring is configured correctly, upstream servers can reject large bodies first.
Examples:
- Nginx
client_max_body_size - API gateway request size limits
- load balancer body constraints
Nginx example:
If proxy limit is lower than Spring limit, request is rejected before it reaches your application.
Exception Handling and User Feedback
Configure exception handling so limit violations are visible and actionable.
Without explicit handling, users may see generic 500 errors that hide the real cause.
End to End Validation
Run upload tests with files below and above the configured limit.
Also check app logs and proxy logs to see which component rejected the request.
Version and Dependency Checks
If you upgraded Spring Boot, verify property namespaces and multipart dependencies. Old tutorials may reference deprecated property keys or resolver classes.
Keep dependency tree minimal. Multiple multipart libraries can lead to confusing behavior if auto configuration chooses an unexpected resolver.
Add Integration Tests for Size Limits
Automated integration tests should upload files around boundary values, including just below limit and just above limit cases. These tests detect regressions when proxy configuration or multipart resolver wiring changes. They also ensure your API consistently returns the expected status code and error payload for oversized uploads.
Keep these tests in CI so configuration drift is caught before production deployments.
Review limits after upgrades.
Common Pitfalls
- Using outdated property names that do not match the Spring Boot version in use.
- Defining a custom multipart resolver and forgetting to set limits in that resolver.
- Testing through a proxy with lower body size limits than the application.
- Forgetting that
max-request-sizemust cover all multipart parts, not only one file. - Returning generic server errors instead of clear payload too large responses.
Summary
- Start with correct
spring.servlet.multipartconfiguration for your Boot version. - Ensure endpoint consumes multipart form data and uses expected resolver path.
- Check proxy and gateway request limits, not only application settings.
- Add explicit exception handling for size violations.
- Validate end to end with real upload sizes and logs at each layer.
Related reading
- SpringBootTest No qualifying bean of type 'org.springframework.test.web.servlet.MockMvc' available
- SpringBootTest vs ContextConfiguration vs Import in Spring Boot Unit Test
- SpringBootTest Vs WebMvcTest DataJpaTest service unit tests, what is the best?
- Springfox 3.0.0 is not working with Spring Boot 2.6.0
- Springfox swagger not working in spring boot 2.2.0
- Springfox Type javax.servlet.http.HttpServletRequest not present
- SpringRunner vs SpringBootTest
- Spring's RequestParam with Enum

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.