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

前端 未结 6 667
有刺的猬
有刺的猬 2020-11-28 08:55

I know there are non-standard frameworks such as commons-validator, and hibernate validator.

I wanted to know if someone knows an implementation of the official stan

相关标签:
6条回答
  • 2020-11-28 09:33

    There are 2 compliant implementations now:

    • Apache Bean Validation (formerly agimatec)
    • Hibernate Validator

    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/

    0 讨论(0)
  • 2020-11-28 09:36

    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.

    0 讨论(0)
  • 2020-11-28 09:39

    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

    0 讨论(0)
  • 2020-11-28 09:47

    Hibernate Validator is the reference implementation of JSR-303

    0 讨论(0)
  • 2020-11-28 09:52

    Implementations:

    • agimatec-validation
    • Hibernate Validator
    0 讨论(0)
  • 2020-11-28 09:57

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

    0 讨论(0)
提交回复
热议问题