Reputation: 376
I'm using spring-boot-starter-web:jar:2.6.2 in my project, this jar uses hibernate-validator:6.2.0.Final. Recently we decided to move to Hibernate 7.0.2.Final, so I added the following maven config:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${rest.starter.version}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.2.Final</version>
</dependency>
But now I get the following error during integration testing or run:
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.
Why does it happen and how to fix it?
Upvotes: 2
Views: 3971
Reputation: 5448
Springinjecter
's answer is correct, but now I think it is better to rely only on Spring-Boot which also has a dedicated validator:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
I prefer that option instead relying on other third party libraries.
Upvotes: 0
Reputation: 56
spring-boot-2.x uses javax.validation Annotations and so you need an implementation for javax.validation.spi.ValidationProvider. hibernate-validator:7.0.2 has moved from javax.validation to jakarta.validation and for that it is not downward compatible.
It depends on your project now: upgrade to spring-boot 3.x ( also upgrade from javax.* to jakarta.* - this might be a huge upgrade ) or downgrade hibernate-validator to version 6.x
I hope I have explained it well :-)
Upvotes: 4