In Spring Boot, @Valid triggers Bean Validation (Jakarta Validation) on an object so that constraints such as @NotBlank, @Size and @Min are checked automatically. Put it on a @RequestBody parameter, and an invalid payload is rejected with 400 Bad Request before your controller code runs. It also cascades into nested objects and lists when you add it to those fields.
For Spring Boot 3 and later the annotation is jakarta.validation.Valid. Spring Boot 2 used javax.validation.Valid, so older examples need updated imports.
Spring Boot does not ship Hibernate Validator in the web starter. Add the validation starter:
Spring Boot then auto-configures a LocalValidatorFactoryBean, and Spring MVC uses it whenever it sees @Valid or @Validated on a handler argument.
Declare constraints on a DTO. A record keeps it compact:
Then add @Valid to the controller parameter:
Posting {"name": "", "email": "nope"} fails before the method body. The exception thrown is MethodArgumentNotValidException.
By default the client receives a 400 with little detail. Map the exception to a structured response with a @RestControllerAdvice:
Sample response body:
@Valid is what cascades validation. Without it on a field, the nested object's constraints are skipped.
Constraints can sit directly on simple parameters:
In Spring Framework 6.1 and later (Spring Boot 3.2+), controllers with constraint annotations on parameters get built-in method validation, and failures raise HandlerMethodValidationException. In earlier versions you had to put @Validated on the controller class, which produced a ConstraintViolationException instead. Handle whichever exception your version throws.
@Valid also works in @ConfigurationProperties classes, so the application fails at startup when configuration is wrong:
@Valid is the standard Jakarta annotation and cascades into nested objects. @Validated is Spring's variant that adds validation groups and enables method validation on a class.
Check that spring-boot-starter-validation is present, that the import is jakarta.validation.Valid, and that the parameter is annotated @RequestBody with @Valid on it.
Only constraints that disallow null do. @Size and @Email accept null, so combine them with @NotNull or @NotBlank.
Wrap the list in a DTO or use List<@Valid Item> with @Validated on the controller class, since @Valid alone does not apply to a bare list parameter.
@Valid in Spring Boot triggers Jakarta Bean Validation on request bodies and nested objects. Add the validation starter, annotate DTO fields, put @Valid on @RequestBody, and turn MethodArgumentNotValidException into a clear ProblemDetail response. For path and query parameters, rely on built-in method validation in recent Spring versions.