本文介绍了javax.validation.NotBlank缺少验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,在公共api模块(多模块项目)中,我不能使用任何形式的hibernate的验证注释,因此我确实使用了javax.validation中的一个可接受的注释.

I have requirement that in common api module(multi module project) I can't use any kind of hibernate's validation annotations, so I did use one from javax.validation which is acceptable.

当我要验证包含NotBlank批注的域对象(我使用vaadin)时,问题开始.我收到以下异常

Problem starts when I want to validate my domain objects(I use vaadin) that contains NotBlank annotation. I get the following exception

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'name'

通过调用调用验证

Validation.buildDefaultValidatorFactory().validateValue(beanType, propertyName, value)

相同的代码与hibernate的NotBlank完美配合

Same code works perfectly with hibernate's NotBlank

javax的@Size @NotNull也可以正常工作.

Also @Size @NotNull from javax works fine.

是否可以将NotBlank验证程序实现提供给DefaultValidatorFactory?

Is it possible to provide NotBlank validator implementation to DefaultValidatorFactory?

我缺少一些依赖吗?(我已经有了hibernate-validator)

Am I missing some dependency?(I have hibernate-validator already)

javax的NotBlank是否与hibernate的NotBlank一样(我是说它可以验证字符串吗?)

Does NotBlank from javax works the same as NotBlank from hibernate(I mean does it validate strings?)

如何解决这个问题?

推荐答案

问题出在您当时使用的版本中.您需要更新到6.0.x系列.目前最新的是6.0.9.请注意,groupId更改为org.hibernate.validator.

The problem is in the version you are using then. You need to update to 6.0.x series. With the current latest been 6.0.9. Note that the groupId is changed to org.hibernate.validator.

<dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.0.9.Final</version>
</dependency>

javax.validation.constraints.NotBlank Bean的一部分验证2.0 及其验证程序在5.3系列中不存在.

the javax.validation.constraints.NotBlankis part of Bean Validation 2.0 and validator for it is not present in 5.3 series.

这篇关于javax.validation.NotBlank缺少验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 17:29