I want to use Hibernate Validator, In first step I checked and studied the following reference :
first sample in page 3 is my problem
I cloud not find this imports packages (javax.validation.*)
in hibernate-validator-5.0.2.Final.jar
I found only (org.hibernate.validator.*) but these classes did not exist
package org.hibernate.validator.referenceguide.chapter01;
import java.util.Set;
// ?????
import javax.validation.ConstraintViolation; // Not Found
import javax.validation.Validation; // Not Found
import javax.validation.Validator; // Not Found
import javax.validation.ValidatorFactory; // Not Found
// ?????
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class CarTest {
private static Validator validator;
@BeforeClass
public static void setUp() {
// ?????
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
// ?????
}
@Test
public void manufacturerIsNull() {
Car car = new Car(null, "DD-AB-123", 4);
Set<ConstraintViolation<Car>> constraintViolations
= validator.validate(car);
assertEquals(1, constraintViolations.size());
assertEquals("may not be null", constraintViolations.iterator().next().getMessage());
}
please help me and guide me what is necessary packages for the following code ?
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
You need to add the validation-api jar to your classpath. The latest version is
validation-api-1.1.0.Final.jar
. The classesjavax.validation.*
are contained in this jar.