Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @构造函数参数的NotNull验证无效_Java_Spring_Notnull_Javax - Fatal编程技术网

Java @构造函数参数的NotNull验证无效

Java @构造函数参数的NotNull验证无效,java,spring,notnull,javax,Java,Spring,Notnull,Javax,我有最后一节课。当我在构造函数上验证我的字段时,有一个NullPointerException。我使用javax.validation.constraints.NotNull。 它仅在我验证构造函数中的字段时发生。当我早些做的时候,这就是工作。你知道为什么吗? //它工作得很好 public final class User { @NotNull private final String name; @NotNull private final List<Notes> note

我有最后一节课。当我在构造函数上验证我的字段时,有一个NullPointerException。我使用javax.validation.constraints.NotNull。 它仅在我验证构造函数中的字段时发生。当我早些做的时候,这就是工作。你知道为什么吗? //它工作得很好

public final class User { 

@NotNull private final String name; 
@NotNull private final List<Notes> notes; 

@JsonCreator public User(String name, List<Notes> notes){ 
this.name = name; 
this.notes = notes }



//It isn`t working, NPException 
public final class User { 

private final String name; 
private final List<Notes> notes; 

@JsonCreator 
public User(@NotNull String name, @NotNull List<Notes> notes){ 
this.name = name; 
this.notes = notes }
公共最终类用户{
@NotNull私有最终字符串名称;
@非空私人最终清单注释;
@JsonCreator公共用户(字符串名称,列表注释){
this.name=名称;
this.notes=notes}
//它不起作用了,是吗
公共最终类用户{
私有最终字符串名;
非公开最后名单说明;
@JsonCreator
公共用户(@NotNull字符串名称,@NotNull列表注释){
this.name=名称;
this.notes=notes}

您认为这些注释的作用是什么?我的确切意思是?检查字段是否为空,然后(如果为空)使用messagge about null字段显示很好的验证错误。在上有一个在构造函数中使用它的示例。您是否在一个使用验证器的环境中运行您的应用程序,该验证器实际检查这些注释?否则,它们只是文本,除了向程序员传达预期用途之外,什么都不做。我只是在spring boot上运行它它只在第一个示例中有效(@NotNull,在字段声明之前),您是否能够让第二个版本正常工作?