自从我决定在我的 GWT 项目中使用 JSR 303 Bean Validation 以来,已经过去了大约 5 个小时,我得说我什至无法(礼貌地)表达我对此有多不满意 蹩脚的文档 关于 Google 网站上的主题。

我真的希望你们能帮助我。

我跟着 这篇博文 将客户端 bean 验证添加到我的项目中。不幸的是,它只工作了一次,并在运行时引发了一个异常,说我需要将 Hibernate 验证源添加到类路径中。我解决了这个问题,并决定重新调整我的依赖关系(我一生中最大的错误),但我无法让它再次发挥作用。

我也无法使用 GWT SDK 中的验证示例,因为它无法编译,因为它有两个类的实现 ServerValidator. 。诡异的。

因此,为了简化我的问题,我使用 IntelliJ IDEA 的项目向导创建了虚拟 GWT 应用程序。

我向模块 xml 添加了以下元素:

<inherits name="org.hibernate.validator.HibernateValidator"/>
<replace-with class="com.mySampleApplication.client.ClientValidatorFactory">
    <when-type-is class="javax.validation.ValidatorFactory"/>
</replace-with>

已创建 ClientValidatorFactory:

package com.mySampleApplication.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.validation.client.AbstractGwtValidatorFactory;
import com.google.gwt.validation.client.GwtValidation;
import com.google.gwt.validation.client.impl.AbstractGwtValidator;

import javax.validation.Validator;
import javax.validation.groups.Default;

public class ClientValidatorFactory extends AbstractGwtValidatorFactory
{
    @GwtValidation(value = {Organization.class}, groups = {Default.class, ClientGroup.class})
    public interface GwtValidator extends Validator
    {
    }

    @Override
    public AbstractGwtValidator createValidator()
    {
        return GWT.create(GwtValidator.class);
    }
}

并且在 onModuleLoad() 方法我添加了这一行,导致编译器崩溃

Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

最后我使用了我复制的以下罐子 来自 GWT SDK 的验证示例.

hibernate-validator-4.1.0.Final-sources.jar
hibernate-validator-4.1.0.Final.jar
log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
validation-api-1.0.0.GA-sources.jar
validation-api-1.0.0.GA.jar

但是当我编译我的项目时,它给出了以下无意义的错误:

enter image description here

在详细的 GWT 编译器日志中,我看到了这一点:

Loaded 2315 units from persistent store.
   Found 2282 cached units.  Used 2282 / 2282 units from cache.
   Added 0 units to persistent cache.
   Validating newly compiled units
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/engine/ConstraintViolationImpl_CustomFieldSerializer.java'
         Line 33: No source code is available for type org.hibernate.validator.engine.ConstraintViolationImpl<T>; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/engine/ValidationSupport.java'
         Line 43: No source code is available for type org.hibernate.validator.engine.ConstraintViolationImpl<T>; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/EmailValidator.java'
         Line 25: No source code is available for type org.hibernate.validator.constraints.Email; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/ScriptAssertValidator.java'
         Line 26: No source code is available for type org.hibernate.validator.constraints.Email; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/URLValidator.java'
         Line 26: No source code is available for type org.hibernate.validator.constraints.URL; did you forget to inherit a required module?
      Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/engine/PathImpl.java'
         Line 72: No source code is available for type org.hibernate.validator.engine.NodeImpl; did you forget to inherit a required module?

为什么找不到课程?我有 hibernate-validator-4.1.0.Final-sources.jar 在我的类路径中。

有什么想法吗 ?

我上传了我的项目 这里 如果你们想玩的话。

有帮助吗?

解决方案

案件结案了,伙计们。错误是由于 IntelliJ IDEA 中的错误导致类路径中缺少休眠验证源而导致的。详细信息是 这里.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top