Backend Development 8 min read

Why @RequestBody Cannot Be Used Multiple Times in a Spring MVC Method – A Deep Dive

This article explains why the Spring MVC @RequestBody annotation cannot be applied to multiple parameters in a single handler method, detailing the internal request‑body reading process, the resulting HttpMessageNotReadableException, and how to correctly handle multiple data parts using a single DTO.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Why @RequestBody Cannot Be Used Multiple Times in a Spring MVC Method – A Deep Dive

In Spring MVC the @RequestBody annotation maps the HTTP request body to a method parameter by reading the input stream once and converting JSON to a Java object via HttpMessageConverter s.

When the annotation is used on multiple parameters in the same method, the first read consumes the stream, leaving no body for the second, which triggers a HttpMessageNotReadableException with the message “Required request body is missing”.

The internal processing involves InvocableHandlerMethod.getMethodArgumentValues , HandlerMethodArgumentResolver , and RequestResponseBodyMethodProcessor.readWithMessageConverters , which checks for a body and throws if it is absent.

Consequently, @RequestBody cannot be repeated in a single handler method; to receive multiple pieces of data you should wrap them in a single DTO or use alternative mechanisms such as multipart requests.

@PostMapping("/duplicate")
public ResponseEntity getBookAndUserInfo(@RequestBody BookInfo bookInfo,
                                        @RequestBody UserInfo userInfo) {
    BookInfoDto bookInfoDto = BookInfoDto.builder()
            .bookInfo(bookInfo)
            .userInfo(userInfo)
            .build();
    return new ResponseEntity(bookInfoDto, HttpStatus.OK);
}

The above code fails because the request body is read only once, causing the second @RequestBody to receive no data.

@PostMapping("/example")
public ResponseEntity
handleRequestBody(@RequestBody SomeObject someObject) {
    // process the request body; SomeObject is a custom Java class
    return ResponseEntity.ok("Success");
}

In this correct example a single DTO ( SomeObject ) encapsulates all needed fields, allowing Spring MVC to bind the request body successfully.

backendJavaDTOHTTPAnnotationSpring MVCRequestBody
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.