GWT 和 Hibernate 验证器
我在使用 Hibernate Validator 和 GWT 2.4 时遇到问题。当模块启动时,我收到错误:
00:00:05,562 [错误] 延迟绑定结果类型 'javax.validation.ValidatorFactory' 不应该是抽象的
java.lang.RuntimeException:延迟绑定失败 'javax.validation.ValidatorFactory'(您是否忘记继承一个 所需模块?) ...
模块配置:
<module rename-to='start'>
...
<inherits name="com.google.gwt.validation.Validation" />
<!-- with this doesn't work too
<inherits name="org.hibernate.validator.HibernateValidator" />
-->
...
</module>
入口点:
public class Start implements EntryPoint {
public void onModuleLoad() {
final ValidatorFactory factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
...
}
}
pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
I have problem with using Hibernate Validator with GWT 2.4. When module is starting i get error:
00:00:05,562 [ERROR] Deferred binding result type
'javax.validation.ValidatorFactory' should not be abstractjava.lang.RuntimeException: Deferred binding failed for
'javax.validation.ValidatorFactory' (did you forget to inherit a
required module?)
...
module configuration:
<module rename-to='start'>
...
<inherits name="com.google.gwt.validation.Validation" />
<!-- with this doesn't work too
<inherits name="org.hibernate.validator.HibernateValidator" />
-->
...
</module>
entry point:
public class Start implements EntryPoint {
public void onModuleLoad() {
final ValidatorFactory factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
...
}
}
pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决了这个问题!
根据 http://code.google.com/p/google-web -toolkit/wiki/BeanValidation 我必须实现自定义
MyValidatorFactory
并添加到项目 hibernate-validator 源 .jar。GWT 模块配置:
MyValidatorFactory
还需要
Hibernate 验证器源使用:
SOLVED this!
According to http://code.google.com/p/google-web-toolkit/wiki/BeanValidation i had to implement custom
MyValidatorFactory
and add to project hibernate-validator sources .jar.GWT module configuration:
MyValidatorFactory
Hibernate validator sources are needed also
Using:
上次我尝试完成这项工作时,我非常头疼,并决定自己基于 JSR303 标准实现 GWT 验证框架。
无论如何,这仍然是一个实验性框架,如 Wiki 中所述:
http: //code.google.com/p/google-web-toolkit/wiki/BeanValidation
警告
实验性的。 API 可能会更改。有些事情仍然不起作用。
所以,如果我是你,我就不会尝试让它发挥作用。为自己实现一些能够验证您的类的生成器。
我还在这里尝试了这个框架:
http://code.google.com/p/gwt-validation /
...但是,完全没能让它为我工作!但根据您的情况,它可能工作得很好......尝试制作一个“非常”小的应用程序来测试不同的方法,看看什么适合您。
Last time I tried to make this work, I just had a huge headache and decided to implement the GWT-validation framework myself, based on the JSR303 standard.
Anyway, this is still an experimental framework, as stated in the Wiki:
http://code.google.com/p/google-web-toolkit/wiki/BeanValidation
WARNING
EXPERIMENTAL. The API may change. SOME things still just don't work.
So, if I were you, I wouldn't try to make it work. Implement yourself some generator that is capable of validating your classes.
I also tried this framework here:
http://code.google.com/p/gwt-validation/
... but again, totally failed to make it work for me! But depending on your cases, it might work fine... try to make a "very" small application to test the different approaches and see what works for you.