I needed to limit the size of the client request body, so I used this configuration.

https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.server.server.undertow.max-http-post-size

SpringBoot Version

2.5.2

POM

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.2</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

application.yaml

server:
  port: 80
  max-http-header-size: 1KB
  undertow:
    max-http-post-size: 10B # Request body maximum 10 bytes

Controller

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class IndexController {

    // Take the request body from the client and respond to the client
    @PostMapping(value = "/p")
    public Object tesr (@RequestBody String body) {
        return ResponseEntity.status(HttpStatus.OK).header(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8").body(body);
    }
}

Test

After the server started normally, I tried to launch a request with the client and the request body was larger than the maximum bytes in the configuration (10 bytes).

SpringBoot configuration item: server.undertow.max-http-post-size does not take effect

I thought that there would be anomalies occurring in this case. and the server responds with: 413 status code, but as you can see. Everything seems to be fine.

Is there something wrong with my understanding of this configuration? Any help would be greatly appreciated.

Comment From: wilkinsona

Duplicate of #18555.