经过一年的努力开发以及自上一次修订之后的四年多时间,Bean Validation 2.0 (JSR 380) 的最终正式版终于发布了。 上周,JCP 执行委员会以 25 票赞成票一致通过了 JSR 的最终批准投票。投票结束后,就发布了 2.0.0 版本的规范、API 和 TCK。与此同时,参考 Bean Validation 最终版本的实现,Hibernate Validator 6 最终版也发布了。 接下来的几天内,最终的规范将在 jcp.org 上的 JSR 380 页面提供。 Bean Validation 2.0 的新特性概览: Support for validating container elements by annotating type arguments of parameterized types, e.g. List<@Positive Integer> positiveNumbers; this also includes: More flexible cascaded validation of collection types; e.g. values and keys of maps can be validated now: Map<@Valid CustomerType, @Valid Customer> customersByType Support for java.util.Optional Support for the property types declared by JavaFX Support for custom container types by plugging in additional value extractors Support for the JSR 310 date/time types for @Past and @Future; fine-grained control over the current time and time zone used for validation New built-in constraints: @Email, @NotEmpty, @NotBlank, @Positive, @PositiveOrZero, @Negative, @NegativeOrZero, @PastOrPresent and @FutureOrPresent All built-in constraints are marked as repeatable Parameter names are retrieved using reflection ConstraintValidator#initialize() is a default method Bean Validation 2.0 也将成为 Java EE 8 规范的一部分,它将在今年夏天发布。 来自:http://beanvalidation.org/ Bean Validation 2.0 发布,并通过 JCP 投票成为规范下载地址