Java Reference
In-Depth Information
@Singleton
@Startup
public class InjectValidators {
private Logger logger
=Logger.getLogger(InjectValidators.class.getName());
@Inject
private Validator validator;
@PostConstruct
public void init() {
Student student = new Student();
Set<ConstraintViolation<Student>>
violations =validator.validate(student);
logger.info("InjectValidators-Number of
violations : " +violations.size());
}
}
Support for method and constructor validation
The Bean Validation Specification 1.1 has added the ability to define constraints on
the parameters of a method or constructor. It also allows the definition of the con-
straints on the return value of a method. The following code demonstrates how to
declare and validate constraints on the parameters of a method and its return value:
@Singleton
@Startup
public class ParameterConstraints {
private Logger logger
=Logger.getLogger(InjectValidators.class.getName());
@Inject
ExecutableValidator validator;
@PostConstruct
public void init() {
try {
Search WWH ::




Custom Search