Skip to content

Exception for validation failure in WebFlux does not match the documentation #33061

@xinxiong-tw

Description

@xinxiong-tw

Affects: <Spring Framework 6.1.8 and maybe other versions>


I write a simple demo below, I write a Controller with a handler method receiving a post request and consume a valid request body

@RestController class Controller { @PostMapping("/test") fun test(@RequestBody @Valid foo: Foo) { println(foo) } @ExceptionHandler(Exception::class) fun handleException(e: Exception) { println(e) } } data class Foo( @field:NotEmpty val name: String )

Then I send a post request with this body to the application.

{ "name": "" }

Check out the console and you can see a exception printed and it's type is WebExchangeBindException
But according to the spring document validation, it should throw a MethodArgumentNotValidException.
image

I also test this behavior in mvc and it's the expected exception.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions