javax.validation.Validator.validator.validate(object, groups) bean验证注解报错,异常:
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.messageinterpolation.InterpolationTerm at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateExpression(ResourceBundleMessageInterpolator.java:227) at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolateMessage(ResourceBundleMessageInterpolator.java:187) at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.interpolate(ResourceBundleMessageInterpolator.java:115) at org.hibernate.validator.internal.engine.ValidationContext.interpolate(ValidationContext.java:370) at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolation(ValidationContext.java:284) at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:246) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:289) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:133) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91) at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:478) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:424) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:388) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:340) at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:158) at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:136) at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:102) at org.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:228) at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:115) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
源码位置:
private String interpolateExpression(String message, Pattern pattern, Context context, Locale locale) { Matcher matcher = pattern.matcher( message ); StringBuffer sb = new StringBuffer(); while ( matcher.find() ) { String match = matcher.group( 1 ); InterpolationTerm expression = new InterpolationTerm( match, locale ); if ( expression.needsEvaluation() ) { String resolvedExpression = expression.interpolate( context ); resolvedExpression = Matcher.quoteReplacement( resolvedExpression ); matcher.appendReplacement( sb, resolvedExpression ); } } matcher.appendTail( sb ); return sb.toString(); }
原因:name值为空,有@Length时,需要@NotNull属性,否则会抛出异常
//@NotNull(message = "样品名称为空或不存在") @Length(min=1, max=200) @ExcelField(title="样品名称", align=2, sort=10) public String getName() { return name; }
时间: 2024-10-09 04:51:36