Free auditStart free
GuideError · HTTP status codes

400 Bad Request in Spring Boot

Map a Spring MVC 400 to its exception: unreadable JSON body, failed @Valid, missing parameter, type mismatch. Includes ProblemDetail error handling code.

3 min
read
3
sources
Oct 31, 2026
updated
Scaplet Editorial Team
author
The short answer

Spring MVC turns a fixed list of exceptions into 400: HttpMessageNotReadableException for an unreadable body, MethodArgumentNotValidException for failed bean validation, MissingServletRequestParameterException, TypeMismatchException and a few others. Find the exception in your logs, then fix the request or handle that exception to return a useful body.

  1. The seven exceptions behind a Spring MVC 400
  2. Reproduce and check it in 2 minutes
  3. Handle it once, for every controller
  4. What it means for SEO and crawlers
30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
02Check it

Reproduce and check it in 2 minutes

Then fire three requests at your own app to see three different causes. These need a running application (replace the port and routes with your own):

Your own app: unreadable body, then a bad type, then a missing parameter
# 1. Malformed JSON body -> HttpMessageNotReadableException
curl -s -i -X POST -H 'Content-Type: application/json' -d '{"name": ' http://localhost:8080/api/items

# 2. Text where the handler expects an int -> TypeMismatchException
curl -s -i http://localhost:8080/api/items?page=abc

# 3. Required parameter left out -> MissingServletRequestParameterException
curl -s -i http://localhost:8080/api/search
# Expect: HTTP/1.1 400 on each; the log line names the exception class

If a request returns 400 and the log shows none of the classes in the table, the 400 is coming from somewhere else, such as the embedded server rejecting a malformed request line, or your own code throwing a ResponseStatusException.

Public endpoint: a known 400
curl -s -o /dev/null -w "%{http_code}\n" https://httpbin.org/status/400
# Expect: 400
03Your call

Handle it once, for every controller

Every Spring MVC exception implements ErrorResponse, which carries the status, headers and an RFC 9457 body. The reference documentation's one-step fix is to extend ResponseEntityExceptionHandler in a @ControllerAdvice:
If this fits

Fix the client when

  • The body is not valid JSON or has the wrong field types
  • A required parameter or header is missing
  • Your API contract says the request is wrong
Or

Change the server when

  • A well-formed request is rejected by a constraint that is too strict
  • Callers cannot tell why they got 400 because the body is empty
  • You return 400 from your own code where 404 or 409 fits
Enable RFC 9457 problem responses for all built-in exceptions
@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
}

The status of the response is the status property of the ProblemDetail. To add your own exception with extra fields, return a ProblemDetail from an @ExceptionHandler. This adapts the docs' example to a 400:

A custom exception mapped to 400 with a non-standard field
@ExceptionHandler(InvalidFilterException.class)
public ProblemDetail handleInvalidFilter(InvalidFilterException ex) {
    ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, ex.getMessage());
    pd.setProperty("field", ex.getField()); // non-standard field
    return pd;
}
04Explained

What it means for SEO and crawlers

Google's documentation says it does not use content from, and does not index, URLs that return a 4xx status, and that 4xx codes other than 429 do not affect crawl rate. An API behind a Spring Boot app is rarely crawled, but a server-rendered page returning 400 for an optional query parameter is. Make optional parameters optional with required = false or a default, so a crawler that drops a parameter still gets a page. For the auth cousins of this error, see 401 in Spring Boot and 403 in Spring Boot.
Sources · 3

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • spring.io
  • google.com
  1. 01Spring Framework API: DefaultHandlerExceptionResolverdocs.spring.io · checked 2026-11-01
  2. 02Spring Framework reference: Error responses (RFC 9457)docs.spring.io · checked 2026-11-01
  3. 03How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Questions

Asked a lot.

2 questions people ask next, answered from the sources on this page.

01Why does a failed @Valid return 400 and not 422?

Spring MVC maps MethodArgumentNotValidException to 400 in DefaultHandlerExceptionResolver. You can return a different status from your own handler if your API contract prefers it.

02How do I see which exception caused the 400?

Look for the exception class name in the application log. Spring resolves it before the controller runs, and the class name tells you which row of the mapping applied.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane