以下是我们尝试对整数类型的大小和模式进行验证时遇到的错误。 你能建议吗,我们需要在 validator bean.xml 中为 Integer 类型设置大小和模式验证
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 类型是否不能应用于 Pattern 约束?它可以解释为什么会抛出 UnexpectedTypeException,因为只有在注释的类型与约束规范不匹配时才会抛出它。
我发现 EE7 的模式约束如下:“带注释的 CharSequence 必须匹配指定的正则表达式。正则表达式遵循 Java 正则表达式约定,请参阅模式。 接受字符序列。 null 元素被认为是有效的。”
来源:http://docs.oracle.com/javaee/7/api/javax/validation/constraints/Pattern.html
在 EE6 中,它似乎仅限于字符串:“带注释的字符串必须……接受字符串。空元素被认为是有效的。”
来源: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 的引用资料,证实了这一点 :)
关于javax.验证.UnexpectedTypeException : No validator could be found for type:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26772748/