spring 验证框架出现错误ValidationMessages not found排查

错误如下:

2017-06-14 12:41:03,857 DEBUG [org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl] - Adding composing constraint: ConstraintDescriptorImpl{annotation=javax.validation.constraints.Pattern, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={flags=[Ljavax.validation.constraints.Pattern$Flag;@5c786553, groups=[Ljava.lang.Class;@313a809b, regexp=.*, message={javax.validation.constraints.Pattern.message}, payload=[Ljava.lang.Class;@22cd212b}, constraintType=GENERIC}.

2017-06-14 12:41:03,970 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] - ValidationMessages not found.
2017-06-14 12:41:03,977 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] - ContributorValidationMessages not found.

2017-06-14 12:41:03,983 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] - org.hibernate.validator.ValidationMessages found.


因为在controller参数中用了多个ModelAttribute,并且需要验证,所以一直以为是多个ModelAttribute导致的。

后来,发现,是因为验证字段的类型与验证内容不匹配导致。如下

@NotNull(message = "是否激活不能空")
@ApiModelProperty(required = true, value = "激活")
@Pattern(regexp = "^[0-9]*[1-9][0-9]*$", message = "激活必须是数字")
private int is_active;

is_active是int类型,而@Pattern对int类型无效,所以,一只报错


猜你喜欢

转载自blog.csdn.net/cin_ie/article/details/73216846