Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring: java: package javax.validation.constraints does not exist

Tags:

java

spring

maven

I already have this dependency in my pom.xml file

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

And have refreshed Maven and already restarted IntelliJ but always get this error java: package javax.validation.constraints does not exist

It cannot find this package for some reason. But this error occurs only when I try to compile.

In my Entity class I imported import javax.validation.constraints.Size;

and want to add an annotation to a column for example:

@Size(min = 1)
private String name;

or

@DecimalMin("0.01")
private BigDecimal amount;

But always I get the problem with the validation package.

There is no error message in the IDE, the error appears when I run.

like image 680
Haidepzai Avatar asked Apr 27 '21 13:04

Haidepzai


2 Answers

Validation Starter no longer included in web starters from the Spring Boot version 2.3 : https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters

you should add it yourself.

like image 67
Kimo_do Avatar answered Sep 21 '22 08:09

Kimo_do


I used it like this in my Spring app and it worked.

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>
like image 27
sproketboy Avatar answered Sep 20 '22 08:09

sproketboy