我正在尝试使用带有Java 11(没有Spring或SpringBoot)的Hibernate验证器,但它似乎找不到适当的依赖项组合。我有以下依赖项
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</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>
我得到了这个错误:
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.
我似乎找不到合适的组合
我使用的代码是
Validator VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<T>> constraintViolations = VALIDATOR.validate(object);
更新
这是我试过的所有方法。我几乎把厨房的洗涤槽都扔进去了,但总是收到同样的错误
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.0.Final</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.hibernate.validator</groupId>-->
<!-- <artifactId>hibernate-validator-annotation-processor</artifactId>-->
<!-- <version>8.0.0.Final</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<version>5.0.0-M1</version>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>5.0.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.glassfish.expressly</groupId>-->
<!-- <artifactId>expressly</artifactId>-->
<!-- <version>5.0.0</version>-->
<!-- </dependency>-->
2条答案
按热度按时间fcwjkofz1#
Hibernate Validator 8基于雅加达。这意味着如果您想要使用它,您应该添加
而不是
如果您想使用javax类,那么您需要使用最新的6.2版本的Hibernate验证器
有关8.0中的文档,请参阅此处-https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-gettingstarted-createproject
cuxqih212#
Hibernate-validator已移至组org.hibernate.validator