以下是当我们尝试对整数类型的大小和模式进行验证时出现的错误。
你能建议一下,我们需要在 validator bean.xml 中设置整数类型的大小和模式验证
05:58:57,342 ERROR [ErrorLoggerEJBInterceptor] Unexpected system error: No validator could be found for type: java.lang.Integer
javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Integer
at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:244)
我正在阅读此内容,但 Integer 类型是否不能应用于模式约束?它可以解释为什么抛出 UnexpectedTypeException ,因为只有当注释的类型与约束规范不匹配时才会抛出它。
我发现 EE7 的 Pattern 约束如下:“带注释的 CharSequence 必须与指定的正则表达式匹配。正则表达式遵循 Java 正则表达式约定,请参阅 Pattern。
接受字符序列。 null 元素被认为是有效的。”
src: http://docs.oracle.com/javaee/7/api/javax/validation/constraints/Pattern.html http://docs.oracle.com/javaee/7/api/javax/validation/constraints/Pattern.html
在 EE6 中,它似乎仅限于字符串:“带注释的字符串必须...接受字符串。空元素被认为是有效的。”
src: http://docs.oracle.com/javaee/6/api/javax/validation/constraints/Pattern.html http://docs.oracle.com/javaee/6/api/javax/validation/constraints/Pattern.html
例子:
@Pattern(regexp = "<insert regex here>")
Integer evaluateMe;
这应该会导致 UnexpectedTypeException,因为 Pattern 约束需要 CharSequence (EE7) 或 String (EE6),但找到 Integer 类型。
输入此内容后,我阅读了 Sridhar DD 的参考文献,这证实了这一点:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)