How to inject spring bean into Validator(hibernate)

ⅰ亾dé卋堺 提交于 2019-12-02 04:05:45

Use Spring Validator, it also implements Bean Validation API.

See 7.8.2 Configuring a Bean Validation Provider:

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html

You can also use it for method validations, see "Spring-driven Method Validation" section in the documentation above.

[UPDATE1]

If you want hibernate to validate on persist you need to set jpa property javax.persistence.validation.factory in your enityManagerFactory:

            <property name="jpaPropertyMap">
              <map>
                <entry key="javax.persistence.validation.factory" value-ref="validatorFactory" />
              </map>
            </property>

You may also need to set validation groups for events, see: http://docs.jboss.org/hibernate/validator/4.1/reference/en-US/html/validator-checkconstraints.html#validator-checkconstraints-orm-hibernateevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!