In Spring Boot, @Valid makes the framework validate an object against its Bean Validation constraints before your code uses it. On a @RequestBody or @ModelAttribute controller parameter, a failed check stops the request and Spring responds with 400 Bad Request, so the handler only sees valid input.
It is the standard way to reject bad API input at the edge of your application. Spring Boot 3 uses the jakarta.validation package, and you need the spring-boot-starter-validation dependency for it to take effect.
@Valid in a controller@Valid versus @Validated in Spring BootInput from clients cannot be trusted. Checking it at the edge keeps malformed data out of your services and database, gives clients a clear error instead of a stack trace, and avoids scattering if (x == null) checks through business code. @Valid lets you declare the rules once, on the DTO, and enforce them everywhere that DTO is accepted.
Since Spring Boot 2.3 the validation starter is no longer included in spring-boot-starter-web, so you add it explicitly.
If constraints seem to be ignored, a missing starter is the first thing to check.
Use @NotBlank for strings: @NotNull accepts an empty string and @NotEmpty accepts a string of spaces.
@Valid in a controllerSending {"name": "", "email": "nope", "age": 10} makes Spring throw MethodArgumentNotValidException before create runs, and the response status is 400. The exception carries one FieldError per violated constraint.
By default the response body is minimal. Spring Boot can produce RFC 9457 problem details if you enable it in application.properties:
For full control over the shape, handle the exception yourself:
@Valid on a field cascades validation into that object. Without it, only the outer class is checked.
@Valid versus @Validated in Spring Boot| Aspect | @Valid | @Validated |
|---|---|---|
| Origin | Jakarta Bean Validation | Spring Framework |
| Validation groups | Not supported | Supported |
| Cascades into nested objects | Yes, when placed on the field | No, it is not for fields |
| Class-level method validation | No | Yes, validates parameters of every method |
For plain @RequestBody validation the two behave the same. Choose @Validated only when you need groups or want constraints on @PathVariable and @RequestParam checked through a class-level annotation (since Spring 6.1, constraints placed directly on controller method parameters are also validated without it).
@Valid check return?400 Bad Request, produced from MethodArgumentNotValidException. If you declare a BindingResult right after the argument, no exception is thrown and you decide the response.
@Valid on a @RequestParam or @PathVariable?Constraints such as @Min go directly on those parameters, not @Valid. Spring 6.1 and later validates them automatically and throws HandlerMethodValidationException (also a 400) on failure.
The usual causes are a missing spring-boot-starter-validation, a missing @Valid on the parameter, or javax.validation imports in a Boot 3 project.
@Valid enough for service-layer validation?Not by itself. For beans called outside a controller, put @Validated on the class so Spring creates a validating proxy.
@Valid runs Bean Validation on controller input and cascades into nested objects. Add the validation starter, declare constraints on a DTO, annotate the parameter with @Valid, and handle MethodArgumentNotValidException in a @RestControllerAdvice to return a clean error. Use @Validated when you need groups or class-level method validation.