Is there an implementation of JSR-303 (bean validation) available?

霸气de小男生 提交于 2019-11-27 00:59:07
skaffman

Hibernate Validator is the reference implementation of JSR-303

bashflyng

There are 2 compliant implementations now:

You can access a benchmark and a quick description of both here: http://carinae.net/2010/06/benchmarking-hibernate-validator-and-apache-beanvalidation-the-two-jsr-303-implementations/

OVaL is not a JSR-303 validator, but it can convert jsr303 constraints into its own.

Spring Framework became JSR303 compliant from version 3 onward I think.

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

Spring Framework 4.0 supports Bean Validation 1.0 (JSR-303) and Bean Validation 1.1 (JSR-349) in terms of setup support, also adapting it to Spring’s Validator interface.

As for summer 2018, there are three specifications that supersed each other:

  • JSR 380 (Bean Validation 2.0)
  • JSR 349 (Bean Validation 1.1)
  • JSR 303 (Bean Validation 1.0)

You can consult the official site for more details.

Hibernate Validator 6.10 is a reference implementation of the newest one (380). It has a great documentation I'd recommend to take a look at (however it's quite big stuff).

CUBA platform docs could give you a much shorter grasp of the topic if you need just a fast intro. CUBA framework is based on Spring and EclipseLink, so the things you've learned could be used on regular Spring+Hibernate projects as well :)

The JSR 349 is supported by older versions of Hibernate Validator and by Apache BVal, both of them are "official".

From ORMs other than Hibernate, EclipseLink supports JSR 349 and can use Validator interface provided by HV.

If it's possible, I would recommend to not use the older version (JSR 303) but switch to 349 or 380 specs. They are quite more mature and rich.

Bean Validation could be used in the project even there is no ORM in it, for example you can use it your Java 2SE or Android apps (see this article), however, this is not the approach Bean Validation was designed for as a primary thing. Although it's possible to use these validators (HV and BVal) just by itself (you'd have to instantiate and call Validator and ExecutableValidator manually), they will really shine working together with frameworks like Hibernate, Spring or CUBA

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