错误 javax.validation.ConstraintViolationException
Posted
技术标签:
【中文标题】错误 javax.validation.ConstraintViolationException【英文标题】:Error javax.validation.ConstraintViolationException 【发布时间】:2017-04-25 09:59:04 【问题描述】:我正在使用 Spring MVC 和 Spring Security 以及休眠。我在保存“密码”时遇到问题,无法判断错误在哪里
提交表单时出现以下错误
nested exception is javax.validation.ConstraintViolationException: Validation failed for classes [com.greensungh.jupiter_SHM.model.UsersInfo] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImplinterpolatedMessage='size must be between 6 and 25', propertyPath=Password, rootBeanClass=class com.greensungh.jupiter_SHM.model.UsersInfo, messageTemplate='javax.validation.constraints.Size.message'
]] with root cause
javax.validation.ConstraintViolationException: Validation failed for classes [com.greensungh.jupiter_SHM.model.UsersInfo] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImplinterpolatedMessage='size must be between 6 and 25', propertyPath=Password, rootBeanClass=class com.greensungh.jupiter_SHM.model.UsersInfo, messageTemplate='javax.validation.constraints.Size.message'
这是我的看法:
<div class="control-group">
<label class="control-label" for="password">Password</label>
<div class="controls">
<form:password path="Password" id="password"
class="form-control span8" />
<div class="has-error">
<form:errors path="Password" class="help-inline" />
</div></div></div>
模型:
@NotEmpty
@Size(min=6, max=25)
@Column(name="PASSWORD", nullable=false)
private String Password;
我的messages.properties
NotEmpty.userInfo.Password=Password must be blank
Size.userInfo.Password=Password must be between 6 to 25 characters long
任何想法
【问题讨论】:
【参考方案1】:我遇到了同样的问题。问题是我将密码最大值设置为 30,同时我使用了 bcrypt 编码器。 Bcrypt 对密码进行哈希处理并将其存储为随机的 60 个字符,这违反了最大大小限制。因此,如果您使用加密增加您的最大值,以便您的加密密码满足大小要求。我希望这有帮助。
【讨论】:
以上是关于错误 javax.validation.ConstraintViolationException的主要内容,如果未能解决你的问题,请参考以下文章