No validator could be found for constraint ‘javax.validation.constraints.Size’

@Size is a Bean Validation annotation that validates that the associated String has a value whose length is bounded by the minimum and maximum values. And as your exception says it does not apply to Integer type. Use: @Range @Column(name= “discount_percentage”) @Range(min=0, max=90) private Integer discountPercentage = 0; Or you cloud also use only @Max … Read more

Spring Boot can’t autowire @ConfigurationProperties

This is expected as @ConfigurationProperties does not make a class a Spring Component. Mark the class with @Component and it should work. Note that a class can only be injected if it is a Component. Edit: From Spring 2.2+ (Reference) @ConfigurationProperties scanning Classes annotated with @ConfigurationProperties can now be found via classpath scanning as an … Read more

Bean Validation Groups – Understanding it correctly

First, here is the javax.validation javadoc When you want to validate a bean, you actually call Validator.validate(T object, java.lang.Class… groups) It will then check the validations constraints of the specified groups. It allows to use several validation cases. What you describe in your question is accurate. Note, if you do not put any group on … Read more

Get field name when javax.validation.ConstraintViolationException is thrown

If you inspect the return value of getPropertyPath(), you’ll find it’a Iterable<Node> and the last element of the iterator is the field name. The following code works for me: // I only need the first violation ConstraintViolation<?> violation = ex.getConstraintViolations().iterator().next(); // get the last node of the violation String field = null; for (Node node … Read more

Customize spring validation error

The JSR 303 default message interpolation algorithm allows you to customize messages by supplying a resource bundle named ValidationMessages. Create a ValidationMessages.properties file in the classpath containing: javax.validation.constraints.NotNull.message=CUSTOM NOT NULL MESSAGE javax.validation.constraints.Size.message=CUSTOM SIZE MESSAGE This changes the default message for the @Size constraint, so you should use the @Size constraint instead of the Hibernate-specific @Length … Read more

javax.validation.ValidationException: Unable to find default provider

See this answer : https://stackoverflow.com/a/3989936/325742 To fix, Add this maven dependency Hibernate Validator Annotation Processor. <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator-annotation-processor</artifactId> <version>4.1.0.Final</version> </dependency> That’s the latest stable version of that artifact, as seen from here Generic way of finding a dependency Let’s say that you got a a NoClassDefFoundError stating that the class org.postgresql.Driver was not found. Use … Read more

javax.servlet.ServletException: HV000030: No validator could be found for type: java.lang.Integer

HV000030: No validator could be found for type: java.lang.Integer That will happen when you use JSR303 bean validation in flavor of Hibernate Validator and you have in your JPA entity the Hibernate-specific @NotEmpty on an Integer property like this: @NotEmpty private Integer some; This is completely wrong. An integer cannot be considered as a string, … Read more

Can you change an annotation message at run time?

Here’s how I was able to do this – @Override public void initialize(FieldMatch constraintAnnotation) { firstFieldName = constraintAnnotation.first(); secondFieldName = constraintAnnotation.second(); thirdFieldName = constraintAnnotation.third(); match = constraintAnnotation.match(); //set a message variable on initialization if(“true”.equals(match)){ message = constraintAnnotation.message(); } else{ message = “{password.error.threeQuestionsSameAnswer}”;} } @Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { Object firstObj … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)