我无法仅使用注释来运行构造函数参数验证。
我的代码:
@Data
@Validated
public class TestConstructorLevel
{
private int a;
private int b;
private Integer nullValue;
public TestConstructorLevel( int a,int b,@NotNull Integer nullValue )
{
this.a = a;
this.b = b;
this.nullValue = nullValue;
}
}
我希望我能在某些服务中工作
new TestConstructorLevel(1,2,null)
由于 @NotNull ,我收到 ConstraintViolationException ,但这不起作用。
当我手动触发验证时,我可以运行它的唯一变体,例如:
validator.forExecutables().validateConstructorParameters(
ReflectionUtils.accessibleConstructor( TestConstructorLevel.class,int.class,Integer.class ),new Object[] { 2,1,null } );
但这不合适。
我尝试将TestConstructorLevel类创建为Spring bean,并且没有任何更改。
所以我的问题是:我需要使用什么批注来触发构造方法上的验证。
PS。这是SpringBoot应用程序