@Validated is Spring's own annotation for enabling validation with extra features that the standard @Valid lacks. Placed on a class, it makes Spring wrap the bean in a proxy that validates method arguments and return values against their constraint annotations. Used on a parameter or method, it also lets you pick validation groups so different constraints apply in different situations.
It lives in org.springframework.validation.annotation.Validated, and it works with Jakarta Bean Validation (jakarta.validation in Spring Boot 3 and later).
| Capability | @Valid | @Validated |
|---|---|---|
| Defined by | Jakarta Bean Validation | Spring Framework |
| Validation groups | No | Yes |
| Enables method validation on a class | No | Yes |
| Cascades into nested fields | Yes (marker on the field) | No, use @Valid on the field |
| Usable on a controller parameter | Yes | Yes |
The key idea is that @Validated on a class activates Spring's MethodValidationPostProcessor, which creates an AOP proxy. Without it, constraints on service method parameters are never checked.
Add the validation starter first (spring-boot-starter-validation). Then annotate the class and put constraints on parameters and return values:
Calling findById(0) throws jakarta.validation.ConstraintViolationException with the violated constraints, and the method body never runs. Because validation works through a proxy, a call from one method to another inside the same class bypasses it (self-invocation), and the class cannot be final if it needs a CGLIB proxy.
Groups let one class carry different rules for different operations. Define marker interfaces, assign constraints to them, and select a group with @Validated:
Constraints without a groups attribute belong to the Default group. When you name a group in @Validated, only that group runs, so include Default.class too if you want both.
Constraints on simple controller parameters, such as @PathVariable @Min(1) long id, need method validation. The behaviour depends on the version:
HandlerMethodValidationException, and class-level @Validated is not needed (and can switch you back to the proxy-based behaviour).@Validated on the controller class. Failures raise ConstraintViolationException.Handle the exception that your version produces:
@Validated on a @ConfigurationProperties class makes Spring Boot check the bound values at startup:
A missing app.client.base-url stops the application with a clear binding error instead of failing later at runtime.
Use @Valid for ordinary request bodies and for cascading into nested objects. Use @Validated when you need groups or when you want constraints on service method parameters checked.
Common causes are missing spring-boot-starter-validation, calling the method from inside the same class, or constraints placed on an implementation instead of consistently on the interface or class that Spring proxies.
Class-level method validation throws ConstraintViolationException. A request body that fails @Validated or @Valid on a controller parameter throws MethodArgumentNotValidException.
No. It targets types, methods and parameters. Use @Valid on a field to cascade validation.
@Validated extends Bean Validation in Spring with validation groups and class-level method validation through a proxy. Use it on services and configuration properties, pick groups for create versus update rules, and remember that Spring 6.1 and later validate controller parameters without it. Keep @Valid for cascading into nested objects.