无法创建 Configuration,因为找不到 Bean Validation 提供程序 – Vaadin 14 Spring Boot

huangapple go评论73阅读模式
英文:

Unable to create a Configuration, because no Bean Validation provider could be found - Vaadin 14 Spring Boot

问题

我遇到了一个问题,因为在 crud.getCrudFormFactory().setUseBeanValidation(true); 这一行上。

错误信息如下:

Caused by: javax.validation.NoProviderFoundException: 无法创建 Configuration,因为找不到 Bean Validation 提供程序。请添加提供程序,比如 Hibernate Validator (RI) 到你的类路径中。

这是因为没有在类路径中找到或初始化 JSR-303 Bean 验证实现。你可以尝试添加 Hibernate Validator (RI) 到你的依赖中来解决这个问题。

要找到 Bean Validator,你可以将以下依赖添加到你的 pom.xml 文件中:

<dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.0.18.Final</version> <!-- 请确保使用适当的版本 -->
</dependency>

这将添加 Hibernate Validator 到你的项目,解决 Bean Validation 的问题。

请注意,具体的版本号可能会根据你的项目配置而有所不同,所以确保使用适当的版本号。

英文:

I'm trying to use CRUD-add-on with Vaadin 14. But when I try to run this view:

@Route(&quot;configuration&quot;)
@JsModule(&quot;./styles/shared-styles.js&quot;)
@CssImport(&quot;./styles/views/main/main-view.css&quot;)
public class ConfigurationView extends AppLayout {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ConfigurationView(YoloObjectService yoloObjectService, ObjectNameService objectNameService) {
		
		System.out.println(yoloObjectService == null);
		System.out.println(objectNameService == null);
		// crud instance
        GridCrud&lt;YoloObjectEntity&gt; crud = new GridCrud&lt;&gt;(YoloObjectEntity.class);

        // grid configuration
        crud.getGrid().setColumns(&quot;email&quot;, &quot;active&quot;, &quot;objectName&quot;, &quot;threshold&quot;);
        crud.getGrid().setColumnReorderingAllowed(true);

        // form configuration
        crud.getCrudFormFactory().setUseBeanValidation(true);
        crud.getCrudFormFactory().setVisibleProperties(&quot;email&quot;, &quot;active&quot;, &quot;threshold&quot;, &quot;objectName&quot;);
        crud.getCrudFormFactory().setFieldProvider(&quot;objectName&quot;, new ComboBoxProvider&lt;&gt;(&quot;Object Name&quot;, objectNameService.findAll(), new TextRenderer&lt;&gt;(ObjectNameEntity::getName), ObjectNameEntity::getName));

        // layout configuration
        setContent(crud);
        crud.setFindAllOperationVisible(false);

        // logic configuration
        crud.setOperations(() -&gt; yoloObjectService.findAll(),
                user -&gt; yoloObjectService.save(user),
                user -&gt; yoloObjectService.save(user),
                user -&gt; yoloObjectService.delete(user)
        );
	}
}

I get this error because of crud.getCrudFormFactory().setUseBeanValidation(true); above.

    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.
	at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:291) ~[validation-api-2.0.1.Final.jar:na]
	at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:103) ~[validation-api-2.0.1.Final.jar:na]
	... 83 common frames omitted

2020-09-22 13:59:37.019 ERROR 10778 --- [nio-8080-exec-3] c.v.flow.server.DefaultErrorHandler      : 

java.lang.IllegalStateException: BeanValidationBinder cannot be used because a JSR-303 Bean Validation implementation not found on the classpath or could not be initialized. Use Binder instead
	at com.vaadin.flow.data.binder.BeanValidationBinder.&lt;init&gt;(BeanValidationBinder.java:85) ~[flow-data-2.3.4.jar:2.3.4]
	at com.vaadin.flow.data.binder.BeanValidationBinder.&lt;init&gt;(BeanValidationBinder.java:61) ~[flow-data-2.3.4.jar:2.3.4]

Here is my pom.xml file:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.example.application&lt;/groupId&gt;
&lt;artifactId&gt;my-project&lt;/artifactId&gt;
&lt;name&gt;My Project&lt;/name&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;properties&gt;
&lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
&lt;vaadin.version&gt;14.3.4&lt;/vaadin.version&gt;
&lt;dl4j-master.version&gt;1.0.0-beta7&lt;/dl4j-master.version&gt;
&lt;sarxos.version&gt;0.3.12&lt;/sarxos.version&gt;
&lt;/properties&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;/parent&gt;
&lt;repositories&gt;
&lt;!-- The order of definitions matters. Explicitly defining central here 
to make sure it has the highest priority. --&gt;
&lt;!-- Main Maven repository --&gt;
&lt;repository&gt;
&lt;id&gt;central&lt;/id&gt;
&lt;url&gt;https://repo.maven.apache.org/maven2&lt;/url&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;
&lt;!-- Repository used by many Vaadin add-ons --&gt;
&lt;repository&gt;
&lt;id&gt;Vaadin Directory&lt;/id&gt;
&lt;url&gt;https://maven.vaadin.com/vaadin-addons&lt;/url&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
&lt;pluginRepositories&gt;
&lt;!-- Main Maven repository --&gt;
&lt;pluginRepository&gt;
&lt;id&gt;central&lt;/id&gt;
&lt;url&gt;https://repo.maven.apache.org/maven2&lt;/url&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;
&lt;dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;vaadin-bom&lt;/artifactId&gt;
&lt;version&gt;${vaadin.version}&lt;/version&gt;
&lt;type&gt;pom&lt;/type&gt;
&lt;scope&gt;import&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;!-- Replace artifactId with vaadin-core to use only free components --&gt;
&lt;artifactId&gt;vaadin&lt;/artifactId&gt;
&lt;exclusions&gt;
&lt;!-- Webjars are only needed when running in Vaadin 13 compatibility 
mode --&gt;
&lt;exclusion&gt;
&lt;groupId&gt;com.vaadin.webjar&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.webjars.bowergithub.insites&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.webjars.bowergithub.polymer&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.webjars.bowergithub.polymerelements&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.webjars.bowergithub.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.webjars.bowergithub.webcomponents&lt;/groupId&gt;
&lt;artifactId&gt;*&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;vaadin-spring-boot-starter&lt;/artifactId&gt;
&lt;exclusions&gt;
&lt;!-- Excluding so that webjars are not included. --&gt;
&lt;exclusion&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;vaadin-core&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.vaadin.artur&lt;/groupId&gt;
&lt;artifactId&gt;a-vaadin-helper&lt;/artifactId&gt;
&lt;version&gt;1.2.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;vaadin-testbench&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.github.bonigarcia&lt;/groupId&gt;
&lt;artifactId&gt;webdrivermanager&lt;/artifactId&gt;
&lt;version&gt;3.8.1&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- Projekt Lombok f&#246;r att slippa Getters and Setters --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- For Detection with DL4J --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
&lt;artifactId&gt;deeplearning4j-datasets&lt;/artifactId&gt;
&lt;version&gt;${dl4j-master.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
&lt;artifactId&gt;deeplearning4j-zoo&lt;/artifactId&gt;
&lt;version&gt;${dl4j-master.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- Camera --&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.github.sarxos&lt;/groupId&gt;
&lt;artifactId&gt;webcam-capture&lt;/artifactId&gt;
&lt;version&gt;${sarxos.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- CRUD --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.vaadin.crudui&lt;/groupId&gt;
&lt;artifactId&gt;crudui&lt;/artifactId&gt;
&lt;version&gt;4.3.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;mysql&lt;/groupId&gt;
&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;defaultGoal&gt;spring-boot:run&lt;/defaultGoal&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;!-- Clean build and startup time for Vaadin apps sometimes may exceed 
the default Spring Boot&#39;s 30sec timeout. --&gt;
&lt;configuration&gt;
&lt;wait&gt;500&lt;/wait&gt;
&lt;maxAttempts&gt;240&lt;/maxAttempts&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;!-- Take care of synchronizing java dependencies and imports in package.json 
and main.js files. It also creates webpack.config.js if not exists yet. --&gt;
&lt;plugin&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;vaadin-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${vaadin.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;prepare-frontend&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;profiles&gt;
&lt;profile&gt;
&lt;!-- Production mode is activated using -Pproduction --&gt;
&lt;id&gt;production&lt;/id&gt;
&lt;properties&gt;
&lt;vaadin.productionMode&gt;true&lt;/vaadin.productionMode&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;flow-server-production-mode&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;jvmArguments&gt;-Dvaadin.productionMode&lt;/jvmArguments&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;com.vaadin&lt;/groupId&gt;
&lt;artifactId&gt;vaadin-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${vaadin.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;build-frontend&lt;/goal&gt;
&lt;/goals&gt;
&lt;phase&gt;compile&lt;/phase&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/profile&gt;
&lt;profile&gt;
&lt;id&gt;it&lt;/id&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;start-spring-boot&lt;/id&gt;
&lt;phase&gt;pre-integration-test&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;start&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;stop-spring-boot&lt;/id&gt;
&lt;phase&gt;post-integration-test&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;stop&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;!-- Runs the integration tests (*IT) after the server is started --&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;integration-test&lt;/goal&gt;
&lt;goal&gt;verify&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;trimStackTrace&gt;false&lt;/trimStackTrace&gt;
&lt;enableAssertions&gt;true&lt;/enableAssertions&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/profile&gt;
&lt;/profiles&gt;
&lt;/project&gt;

Reproduce issue:

To reproduce the issue, run the project and then go to http://localhost:8080 then to the configuration tab and press + sign. Now you will have two errors about Bean Validation.

https://github.com/DanielMartensson/Vaadin-DL4J-YOLO-Camera-Mail-Reporter

Question:

How can I find this Bean Validator?

答案1

得分: 15

以下是您要翻译的内容:

雅加达 Bean 验证(以前称为 Java Bean Validation)是一个 API,您需要提供其实现才能使用它。有两种选择,即 Hibernate Validator 和 Apache BVal。您可以将它们中的任何一个添加到您的 pom.xml 文件中。根据运行时环境的不同,添加方式也不同。由于您似乎在使用 Spring Boot,您可以添加以下依赖:

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

我建议您阅读 这个教程,以快速更好地理解雅加达 Bean 验证。这是一个非常流行的 API,很有可能将来在其他项目中也会遇到它。

英文:

Jakarta Bean Validation (previously Java Bean Validation) is an API, you need to provide an implementation of it in order to be able to use it. There are two, Hibernate Validator, and Apache BVal. You can add any of these to your pom.xml file. Depending on your runtime environment, you add these in different ways. Since it seems you are using Spring Boot, you can add the following dependency:

&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
&lt;/dependency&gt;

I recommend you read this tutorial to quickly get a better understanding of Jakarta Bean Validation. It's a very popular API and it's very likely that you'll find it in other projects in the future.

答案2

得分: 7

在一个教程中已经解释过,您需要有一个可用的 Jakarta Bean Validator 实际实现类。在链接的教程中,列出了一系列可用的依赖项,您可以根据您的环境进行选择使用。无论如何,我建议阅读整个教程。

所以,如果您有一个 Java EE 环境,请将以下内容添加到您的 pom 文件中:

<dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.1.5.Final</version>  <!-- 检查最新版本 https://hibernate.org/validator/documentation/getting-started/ -->
</dependency>

如果您使用 Spring Boot,请尝试以下内容:

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

对于 Java SE,尝试以下内容:

<dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.1.5.Final</version>  <!-- 检查最新版本 https://hibernate.org/validator/documentation/getting-started/ -->
</dependency>

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.el</artifactId>
    <version>3.0.3</version>
</dependency>

请注意,这些代码部分已经被正确翻译。

英文:

As is explained in a tutorial, you need to have an actual implementation class of a Jakarta Bean Validator available. In the linked tutorial there are a list of available dependencies shown that you can use, depending on your environment. I recommend reading the whole tutorial anyway.

So if you have a Java EE environment, add this to your pom:

&lt;dependency&gt;
&lt;groupId&gt;org.hibernate.validator&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
&lt;version&gt;6.1.5.Final&lt;/version&gt;  /* check for the latest version at https://hibernate.org/validator/documentation/getting-started/ */
&lt;/dependency&gt;

If you have Spring Boot, try this one:

&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
&lt;/dependency&gt;

And in case of Java SE, try this:

&lt;dependency&gt;
&lt;groupId&gt;org.hibernate.validator&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
&lt;version&gt;6.1.5.Final&lt;/version&gt;  /* check for the latest version at https://hibernate.org/validator/documentation/getting-started/ */
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.glassfish&lt;/groupId&gt;
&lt;artifactId&gt;jakarta.el&lt;/artifactId&gt;
&lt;version&gt;3.0.3&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年9月22日 20:13:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/64009498.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定