Spring Boot @Valid and @NotBlank not working
Codemia Knowledge Hub ·
The most common reason @Valid and @NotBlank do nothing in Spring Boot is a missing dependency. Since Spring Boot 2.3, spring-boot-starter-web no longer brings in validation, so you must add spring-boot-starter-validation explicitly:
If the dependency is present and validation still does not run, check for a missing @Valid on the controller parameter, the wrong import package (javax vs jakarta), constraints placed on both fields and getters, a missing @Validated on service classes, or a missing @Valid on nested objects.
Cause 1: missing spring-boot-starter-validation
Before Spring Boot 2.3, spring-boot-starter-web pulled in Hibernate Validator transitively. That was removed in 2.3 to reduce unnecessary dependencies, so projects that worked on 2.2 silently lose validation after upgrading.
Maven
Gradle
Then confirm it resolves:
You should see hibernate-validator in the tree. Without it, the annotations compile but have no runtime effect.
Cause 2: no @Valid on the controller parameter
@NotBlank on a field only defines a constraint. Spring validates the incoming object only when the method parameter carries @Valid:
Without @Valid, Spring deserializes the body and skips validation entirely. After the dependency, this is the most common cause.
Cause 3: javax vs jakarta imports
Spring Boot 3.x moved from Java EE (javax.*) to Jakarta EE (jakarta.*). Annotations from the wrong package are in the bytecode, but the validator does not recognize them.
| Spring Boot Version | Correct Import |
| 2.x | javax.validation.constraints.NotBlank |
| 3.x | jakarta.validation.constraints.NotBlank |
An IDE auto-import of the wrong package compiles without errors and silently does nothing. In a codebase migrating to Boot 3, check every file for leftover javax imports.
Cause 4: constraints on fields and getters
Bean Validation supports both field-level constraints (on the field) and property-level constraints (on the getter, not the setter). Pick one style per class and use it consistently. Annotating both a field and its getter validates the value twice.
Annotating fields is the simpler and more common convention. With Lombok's @Data or @Getter, put the annotations on the field, which Lombok leaves untouched when it generates getters.
Cause 5: no @Validated on service classes
In Spring MVC controllers, @Valid works because RequestResponseBodyMethodProcessor handles it. In service classes, @Valid on a method parameter does nothing unless the class has @Validated:
Without @Validated, MethodValidationPostProcessor creates no validation proxy around the bean, so the annotations are never evaluated.
@Valid and @Validated are not interchangeable. @Valid (Bean Validation spec) triggers recursive validation but does not support groups. @Validated (Spring-specific) supports groups and is required for method-level validation in services.
Cause 6: nested objects without @Valid
Constraints inside a nested object are checked only when the field holding it is annotated with @Valid:
The same applies to collections, where each element is validated individually:
Each level of nesting needs its own @Valid, which is easy to miss in deep request structures.
@NotNull is not @NotBlank
@NotNull accepts empty strings (""). @NotBlank rejects null, empty and whitespace-only strings. For user-facing text fields, @NotBlank is almost always what you want.
Returning useful validation errors
A failed @Valid @RequestBody throws MethodArgumentNotValidException, which without a handler becomes a generic 400 with no useful detail. Map the errors to a structured response:
ConstraintViolationException covers @Validated service-layer failures and path or query parameter failures.
Debugging checklist
| Step | Check | Command/Action |
| 1 | Dependency present | mvn dependency:tree | grep hibernate-validator |
| 2 | @Valid on controller parameter | Inspect controller method signature |
| 3 | Correct import package | javax.* for Boot 2.x, jakarta.* for Boot 3.x |
| 4 | Annotations on fields or getters, not both | Inspect DTO/request classes |
| 5 | @Validated on service classes | Inspect service class annotations |
| 6 | @Valid on nested objects | Inspect nested DTO fields |
| 7 | Enable debug logging | Set logging.level.org.hibernate.validator=DEBUG |
Debug logging shows which constraints are evaluated, which objects are validated, and why each validation passes or fails:
Related reading
- Spring Boot Value Properties
- Spring Boot version versus Spring Framework version?
- Spring Boot War deployed to Tomcat
- Spring boot Webclient's retrieve vs exchange
- Spring Boot with Kotlin - Value annotation not working as expected
- Spring Cloud AWS SQS fails to connect to service endpoint locally
- Spring Boot Websockets in Wildfly
- Spring Boot with Apache Tiles
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.