package javax.validation.constraints does not exist error in spring boot 2.3

If you are using validation constraints in your Spring Boot application and just migrated to Spring Boot 2.3. You will face an error saving “javax.validation.constraints does not exist“. It happened to me when I tried to migrate Spring-Boot application to JDK 14 and Spring Boot 2.3.

The problem is not with the code but with the Spring Boot starter Jars restructuring in version 2.3.

Before Spring Boot 2.3, Validator libraries were part of web starter (spring-boot-starter-web) and web flux starter (spring-boot-starter-webflux). It has been observed that many web application does not use validation features. It means validator libraries are added unnecessarily to the web application.

Due to this reason, validator libraries have been removed from these starters. Meaning if you want to use those validator libraries, you need to add it manually. More details about this issue can be found here.

So if you want to resolve this issue, add below starter in your pom, and you are good to go.

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

References

1 Comment package javax.validation.constraints does not exist error in spring boot 2.3

  1. Laide Endeley

    I honestly almost gave up on the tutorial I was following until I saw this post. Super helpful and it worked like magic! Many thanks!

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.