如何启用Spring验证 [英] How to Enable Spring Validation

查看:78
本文介绍了如何启用Spring验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将hibernate-validator.jar和javax.validation-api.jar放入我的类路径中之后,我的旧验证已关闭,并且 org.springframework.dao.DataIntegrityViolationException 替换为 org. hibernate.exception.ConstraintViolationException ,它包装了来自表约束的SQL异常,这引起了很多问题.

After putting hibernate-validator.jar and javax.validation-api.jar in my classpath the my old validation turned off and org.springframework.dao.DataIntegrityViolationException is replaced by org.hibernate.exception.ConstraintViolationException which wraps SQL exception that is coming from table constraints and this is causing a lot of issues.

它会自动打开JSR-303验证,因此不再验证任何内容.

It automatically turned JSR-303 validation on so it doesn't validate anything anymore.

我必须放置这两个jar才能将Jersey升级到2.4,它依赖于这两个jar.

I have to put this two jars to be able to upgrade Jersey to 2.4, it has dependency on these two jars.

将这些属性放入hibernate.properties文件中无济于事,hibernate只会忽略它们,但会在启动时加载这些属性

Putting these properties into hibernate.properties file doesn't help, hibernate simply ignores them but it loads the properties on start-up

从资源hibernate.properties中加载属性:{hibernate.validator.apply_to_ddl = false,hibernate.validator.autoregister_listeners = false等}

loaded properties from resource hibernate.properties: {hibernate.validator.apply_to_ddl=false,hibernate.validator.autoregister_listeners=false etc}

javax.persistence.validation.mode=none
hibernate.validator.autoregister_listeners=false
hibernate.validator.apply_to_ddl=false

我正在将Spring 3.2.4与SessionFactory一起使用,并从其中具有约束的hbm.xml文件映射资源,即hibernate 3.6.9.final,hibernate-validator 5.0.final,javax.validator-api 1.1.0.Final

I am using Spring 3.2.4 with SessionFactory and mapping resources from hbm.xml files with constraints in it, hibernate 3.6.9.final, hibernate-validator 5.0.final, javax.validator-api 1.1.0.Final

当我在类路径中使用hibernate.validator时,我只是想不通如何启用spring验证,将不胜感激.

I just can't figure out how to enable spring validation when hibernate.validator in my classpath, any help will be much appreciated.

推荐答案

在类路径中添加休眠验证器会关闭休眠核心验证,因此我必须添加此属性以将其重新打开

Adding hibernate validator to the classpath turns off hibernate core validation, so I had to add this property to turn it back on

<prop key="hibernate.check_nullability">true</prop>

这篇关于如何启用Spring验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆