If the error is from Spring Boot, you have to add the validation starter.
When the @Valid is not recognized even after cleaning the project the dependency is missing in your pom.xml or gradle file.
For maven project, Add the following spring boot starter to your project pom.xml
Maven Spring Boot Validation Starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Gradle Spring Boot Validation Starter
For Gradle use the following dependency,
compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
In build.gradle it will look like below,
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Avoid adding the dependency manually and use tools like spring initializr or the STS plugin.
STS Edit Spring Boot Starters
If you use Spring Tools 4 plugin or Spring Tool Suite IDE use Edit Starters option to add a new starter dependency.
Expand I/O and Check Validation starter to add the dependency.
After adding the dependency clean the project and restart your spring boot application. Now you will see the error in the import javax.validation.Valid will be disappeared.