BeanValidation 错误 - 在类路径上找不到 JSR 303 Bean 验证实现

问题描述 投票:0回答:2

我正在制作 Vaadin 教程系列。

https://www.youtube.com/watch?v=k-DxZ1reIdM&list=PLcRrh9hGNallPtT2VbUAsrWqvkQ-XE22h&index=11

文字版本:https://vaadin.com/learn/tutorials/modern-web-apps-with-spring-boot-and-vaadin/vaadin-form-data-binding-and-validation?

我正在尝试使用 Binding,但我的终端中出现以下错误:

2020-11-22 09:11:11.012  INFO 38103 --- [nio-8080-exec-2] c.vaadin.flow.spring.SpringInstantiator  : The number of beans implementing 'I18NProvider' is 0. Cannot use Spring beans for I18N, falling back to the default behavior
2020-11-22 09:11:11.373  INFO 38103 --- [nio-8080-exec-2] com.vaadin.validator.BeanValidator       : A JSR-303 bean validation implementation not found on the classpath or could not be initialized. BeanValidator cannot be used.

更多内容如下:

Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.

如何添加 Bean Validation 提供商?我正在使用 vaadin 作为 Maven 项目,与教程中相同。

java spring spring-mvc vaadin bean-validation
2个回答
6
投票

通过添加以下依赖解决

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

0
投票

添加整个

spring-boot-starter-validation
有点矫枉过正了。

您可以简单地添加 hibernate 验证器,它将向您的项目添加最少量的库:

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

此方法是 Vaadin 本身建议的,您可以在 here

看到
© www.soinside.com 2019 - 2024. All rights reserved.