I'm trying to use the Hibernate validator, with Java 11, but it can't seem to find the proper combination of dependencies. I have the following dependencies
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.expressly</groupId>
<artifactId>expressly</artifactId>
<version>5.0.0</version>
</dependency>
I get this error:
Caused by: javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
I can't seem to find the right combination that works
The code I'm using is
Validator VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<T>> constraintViolations = VALIDATOR.validate(object);
CodePudding user response:
hibernate-validator has been moved to group org.hibernate.validator
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.0.Final</version>
</dependency>
CodePudding user response:
Hibernate Validator 8 is based on Jakarta. this means that if you want to use it you should add
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
instead of
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
dependency>
if you want to use the javax classes then you need to go with latest 6.2 version of hibernate validator
see here for 8.0 documentation - https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-gettingstarted-createproject