How to Fix @RequestBody Compatibility and Swagger Timeout Issues in Spring Boot

This article explains why @RequestBody conflicts with Swagger in Spring Boot, outlines two common but cumbersome work‑arounds, describes a Swagger API timeout caused by Groovy's MetaClass, and provides a concise configuration fix that eliminates both the timeout and the compatibility issue.

FunTester
FunTester
FunTester
How to Fix @RequestBody Compatibility and Swagger Timeout Issues in Spring Boot

@RequestBody Compatibility Issue

When adding Swagger to a Spring Boot project, the @requestBody annotation conflicts with Swagger's processing, because Spring MVC's default argument resolver and Swagger require opposite handling of @RequestBody. Two common work‑arounds are:

Separate production and test environments via configuration to avoid the conflict.

Modify the argument resolver priority so that a custom resolver outranks RequestResponseBodyMethodProcessor, allowing @RequestBody on custom parameters while keeping Swagger functional.

Both approaches add complexity and often require additional imports that may introduce version‑compatibility problems, so the author abandoned them.

Swagger API Timeout

The author experienced a severe slowdown when generating Swagger JSON with Swagger 3, taking about 30 seconds locally. Investigation on StackOverflow revealed that Groovy’s groovy.lang.MetaClass is included for every Groovy class, inflating the model size and causing the timeout.

One‑Click Fix

The effective solution, also found on StackOverflow, is to filter out groovy.lang.MetaClass in the Swagger configuration. Adding a simple bean that excludes this type shortens the JSON generation to a few seconds and, as a side effect, also resolves the @requestBody compatibility problem.

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.any())
        .build()
        .ignoredParameterTypes(groovy.lang.MetaClass.class);
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Spring BootAPI documentationGroovySwagger@RequestBody
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

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.