所以我有两个参数由Spring @Value
注解注入。minLength
和maxLength
。逻辑上,minLength
不能高于maxLength
,反之亦然。这就是我尝试过的,但失败了。
在maxLength为0
的情况下抛出异常,但在我的application.properties
中,我将其设置为7
(在验证之前进行了测试)
private int minLength;
private int maxLength;
@Min(5)
@Value("${ com.manudcamera.webapi.uuid.minLength : 5} ")
private void setMinLength(int minLength) {
if ( minLength > this.maxLength ) throw new IllegalArgumentException("minimum length cannot be greater than maximum length | min len: " + minLength + " max len: " + this.maxLength);
this.minLength = minLength;
}
@Max(50)
@Value("${ com.manudcamera.webapi.uuid.maxLength : 15 }")
private void setMaxLength(int maxLength) {
if ( maxLength < this.minLength ) throw new IllegalArgumentException("maximum length cannot be greather than minimum length | min len: " + minLength + " max len: " + maxLength);
this.maxLength = maxLength;
}
发布于 2017-08-16 05:34:16
抱怨0的是您的自定义验证码,因为在调用setMinavalue时maxLength值尚未设置(0也是如此)。
一种可能的方法是在执行交叉验证的自定义方法上使用PostConstruct注释。
另一种可能的方法是实现您自己的自定义验证器(将在类级别应用),该验证器执行跨域验证。
发布于 2017-08-16 05:57:59
您可以在bean类中添加以下注释。
@PropertySource(value = {"classpath:application.properties"})
并查看结果。
https://stackoverflow.com/questions/45705460
复制