Javax @NotNull annotation usage
To activate parameter validation, simply annotate the class with @Validated
import org.springframework.validation.annotation.Validated;
From The Java EE 6 Tutorial:
The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean.
You should place your validation of a field related to a declared bean, something like this:
@Entity
@Table(name="users")
public class BackgammonUser {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long userId;
@Column(name="username")
@NotBlank
private String userName;
@NotBlank
private String password;
@NotNull
private Boolean enabled;
}
The BackgammonUser is considered to be a bean.