'Mandatory Validation for pathVariable not working

Currently we are adding mandatory validation for pathVariable - having customized message in response.

When @PathVariable is removed, then it is giving 404 error and not going into any of the exceptionHandler. Can you please help to resolve this issue?

@PostMapping(path = "{id}")
public ResponseEntity<String> migrate(@PathVariable(value = "id")
         @Size(min = 1, max = 64, message = INVALID_FIELD_LENGTH_DETAILS)
         String id) {
    ...
}

Error response as below:

{
 "timestamp": "2022-02-08T15:26:58.649+00:00",
 "status": 404,
 "error": "Not Found",
 "message": "",
 "path": "/migrations"
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source