Validation form in Spring using @Valid not work

Are you sure that the validations don't work? Unless you have for example StringTrimmerEditor registered, your fields will actually be String instances with length equal to 0, not null values when you submit the form and therefore the annotation would consider such values to be valid.

If you want to validate that String is not blank (not null and not an empty String), use for instance the @NotBlank annotation. Also I just tried it myself and the @Email annotation also passes for empty Strings, which would mean that your empty form IS actually valid right now.


After upgrading my project to Spring Boot 2.3.0, I struggled for hours with the same issue until I realized that as of #19550, Web and WebFlux starters do not depend on the validation starter by default anymore. If your application is using validation features, you’ll need to manually add back a dependency on spring-boot-starter-validation in your build file.


I had the same error (the application did not validate).

I added

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

and worked!


I struggled with the same issue in my Spring Boot 2.4.1 project. You'll need to add this dependency in your pom.xml file

...
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-validation</artifactId>
</dependency>
...