美文网首页
@Constraint(validated by = {})

@Constraint(validated by = {})

作者: 雨夏_ | 来源:发表于2023-01-16 17:31 被阅读0次

The javax.validation.constraints leaves the validators to the implementation. Hibernate provides validators to these constraints, and registers them when bootstrapping.

You can set the validators via XML without using @Constraint(validatedBy = { }). However, this is usually used to add to/replace the provided validators with your own. I'm not sure how it will help you since you still need to reference the constraint validator.

Example of using XML constraint definition:

<constraint-definition annotation="org.mycompany.CheckCase">
    <validated-by include-existing-validators="false">
        <value>org.mycompany.CheckCaseValidator</value>
    </validated-by>
</constraint-definition>

See: Configuring via XML

The upcoming 5.2 release provides more ways such as using a service loader or implementing ConstraintDefinitionContributor. See: Providing constraint definitions

转载:https://stackoverflow.com/questions/26544588/hibernate-validator-to-validate-constraints-if-constraintvalidated-by

相关文章

网友评论

      本文标题:@Constraint(validated by = {})

      本文链接:https://www.haomeiwen.com/subject/diwzcdtx.html