The @Valid annotation tells Spring to run Bean Validation on an object: every constraint annotation on its fields (@NotBlank, @Size, @Email, and so on) is checked, and the call fails if any constraint is violated. It comes from the Jakarta Bean Validation specification, not from Spring, and Spring integrates it into controller arguments, @ConfigurationProperties classes and validated method calls.
In Spring Boot 3 and Spring Framework 6 the package is jakarta.validation, not javax.validation. If you see javax.validation.Valid in older tutorials, that is the pre-Jakarta EE 9 name and it no longer works with current Spring.
@Valid does@Valid does@Valid is a marker. On its own it checks nothing; it asks the validation engine (Hibernate Validator in a typical Spring setup) to evaluate the constraints declared on the annotated object. It has two jobs:
@RequestBody DTO or a form-backing object.It does not accept validation groups. If you need groups, use Spring's own @Validated instead.
In Spring Boot, add the validation starter. It brings Hibernate Validator and the Jakarta Validation API, and Boot auto-configures a LocalValidatorFactoryBean for you.
Without this dependency, constraint annotations compile (if the API is on the classpath) but are silently never evaluated, which is a common reason why validation "does nothing".
Declare constraints on the DTO. A record works well because the constraints sit on the components.
Then put @Valid on the controller parameter.
When validation fails, Spring MVC throws MethodArgumentNotValidException before your method body runs, and the default handler responds with 400 Bad Request. Your method only executes with data that already satisfies every constraint.
If you add a BindingResult parameter directly after the validated argument, Spring does not throw. It hands you the errors instead, which is the classic pattern for server-rendered forms.
For a JSON API, a central handler is cleaner than BindingResult in every method:
Validation does not descend into nested objects automatically. Mark the field or component with @Valid to cascade.
Here the address constraints are checked with the order, and List<@Valid Item> validates each element. Without the @Valid on address, a blank city would pass unnoticed.
You can also call the validator directly, for example in a batch job or a service that builds objects itself.
@Valid work without spring-boot-starter-validation?No. The annotation compiles if the Jakarta Validation API is present, but no provider is available to evaluate constraints, so nothing is checked. Add the starter.
@Valid and @Validated?@Valid is the standard Jakarta annotation and supports cascading. @Validated is Spring's variant: it adds validation groups and, on a class, enables method-level validation. See the dedicated comparison for details.
Cascading is opt-in. Put @Valid on the nested field, or on the type argument such as List<@Valid Item>.
javax.validation import errors?Spring Boot 3 and Spring Framework 6 use the jakarta.validation namespace. Replace the imports and update any library that still targets javax.
@Valid triggers Jakarta Bean Validation on a method argument and cascades into nested objects. Add spring-boot-starter-validation, import from jakarta.validation, put constraints on your DTO, and mark controller parameters with @Valid. Handle failures with a @RestControllerAdvice or a BindingResult, and use @Validated when you need groups.