This annotation is part of the Java Bean Validation specification. In order to see these messages, you need to pass an invalid object through the validator. In the case of a container (web server), this validator can be invoked transparently. Here is an example of a function that validates a passed object and throws an exception if it is not valid.
public static <T extends Object> void validate( T object ) throws RuntimeException{ ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<T>> valRes = validator.validate( object ); if( ! valRes.isEmpty() ){ StringBuilder sb = new StringBuilder("Validation failed for: "); sb.append(object); for( ConstraintViolation<T> fail : valRes) { sb.append("\n ").append( fail.getPropertyPath() ).append(" ").append( fail.getMessage() ); } throw new RuntimeException( sb.toString() ); } }
As a class for type T you can use any class whose fields are labeled, for example, with the annotation @NotNull .
PS In general, these annotations should not be installed on static fields.