hibernate-validator

Exception in hibernate-validator. nested exception is java.lang.NoClassDefFoundError: ConfigurationImpl

你说的曾经没有我的故事 提交于 2019-11-29 14:35:47
Details: I am making form-validation using javax-validation and hibaernate-validator in Spring. Other than basic necessary JAR files for Spring. I have included: validation-api-1.1.0.Final hibernate-validator-5.1.0.Final I read somewhere that spl4j version is also in concern: so I'm also telling: ###slf4j-api-1.7.5### ###slf4j-simple-1.7.5### ###log4j-1.2.17### Can the cause of error be due to slf4j and log4j compatibility? I use annotation base validation. Let me provide some code: Customer.java import java.util.Date; import javax.validation.constraints.Max; import javax.validation

Spring Rest Controller: how to selectively switch off validation

自古美人都是妖i 提交于 2019-11-29 13:42:27
In my controller I have a method for creating an entity import javax.validation.Valid; ... @RestController public class Controller { @RequestMapping(method = RequestMethod.POST) public ResponseEntity<?> create(@Valid @RequestBody RequestDTO requestDTO) { ... with import org.hibernate.validator.constraints.NotEmpty; ... public class RequestDTO @NotEmpty // (1) private String field1; //other fields, getters and setters. I want to add a controller method update(@Valid @RequestBody RequestDTO requestDTO) but in this method it should be allowed for field1 to be empty or null, i.e. the line

Hibernate-validator Groups with Spring MVC

拈花ヽ惹草 提交于 2019-11-29 12:24:52
I'm using hibernate-validator 4.3.1 and Spring MVC 3.2.3. My application has a bean with the following properties and annotations (I've removed most of them to make it simple): public class Account { @NotEmpty(groups = GroupOne.class) private String name; @NotEmpty(groups = GroupOne.class) private Date creationDate; @NotEmpty(groups = GroupTwo.class) private String role; @NotEmpty(groups = GroupTwo.class) private String profile; //getters and setters } As it is showed, there are two groups of validations because the application has a wizard-form composed of two steps: in the first step the

Spring Boot - Hibernate custom constraint doesn't inject Service

跟風遠走 提交于 2019-11-29 12:17:09
I will try to ignore other details and make it short: @Entity public class User @UniqueEmail @Column(unique = true) private String email; } @Component public class UniqueEmailValidatior implements ConstraintValidator<UniqueEmail,String>, InitializingBean { @Autowired private UserService userService; @Override public void initialize(UniqueEmail constraintAnnotation) { } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if(userService == null) throw new IllegalStateException(); if(value == null) return false; return !userService.isEmailExisted(value); } } This

spring validation with @valid where/how custom error messages

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 12:09:30
I'm trying to do some spring validation with the error messages in properties files. But the examples I find all seem to have the values hardcoded, or gotten from a properties file but using a validator class and retrieving it there. My setup is a bit different. I'm using the @Valid annotation in my requestmapping, and my @Valid class uses @NotNull etc. I've seen some examples where people do @NotNull(message = "blablabla"); But that's also hardcoded, and I'd like to put the messages in a properties file so I can easily edit it on the fly and so I can easily implement i18n in the future. Any

Is there a standard way to enable JSR 303 Bean Validation using annotated method arguments

丶灬走出姿态 提交于 2019-11-29 08:23:16
问题 I've been looking a around for a while now with no luck. I'n not using Spring MVC but still want to use @javax.validation.Valid to enable validation of method arguments. To give an example public class EventServiceImpl implements IEventService { @Override public void invite(@Valid Event event, @Valid User user) { ... } } Using MVC, this is enabled for @Controller annotated beans with a simple <mvc:annotation-driven/> (see 5.7.4.3 Configuring a JSR-303 Validator for use by Spring MVC). Using

JSR-303 bean validation with Spring does not kick in

痴心易碎 提交于 2019-11-29 07:37:01
I've configured a JSR-303 custom validator following what's given in the docs ( http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/validation.html ), complete with LocalValidatorFactoryBean and Hibernate validator on the classpath. However, my validator just refuses to kick in. I've put up a dirt simple test project here ( https://github.com/abhijitsarkar/java/tree/master/spring-jsr-303 ), along with a failing unit test. Should you decide to take a look, just clone it and run gradlew clean test from the root directory. I'm using Spring framework 4.0.2.RELEASE and Hibernate

Using a custom ResourceBundle with Hibernate Validator

拜拜、爱过 提交于 2019-11-29 07:36:57
问题 I'm trying to set up a custom message source for Hibernate Validator 4.1 through Spring 3.0. I've set up the necessary configuration: <!-- JSR-303 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="validationMessageSource" ref="messageSource"/> </bean> The translations are served from my message source, but it seems that the replacement tokens in the messages themselves are looked up in the message source, i.e. for a: my

Validating double and float values using Hibernate Validator - bean validation

耗尽温柔 提交于 2019-11-29 02:53:14
问题 I'm looking for a way to validate a java.lang.Double field in the Spring command bean for its maximum and minimum values (a value must lie between a given range of values) like, public final class WeightBean { @Max(groups={ValidationGroup.class}, value=Double.MAX_VALUE, message="some key or default message") @Min(groups={ValidationGroup.class}, value=1D, message="some key or default message") private Double txtWeight; //Getter and setter. public interface ValidationGroup{} } But both @Max and

Control validation annotations order?

旧城冷巷雨未停 提交于 2019-11-29 01:31:59
i have a field that have two validation annotations @NotEmpty @Length(min=3,max=100) String firstName; i am just curious to know how hibernate is specifying the order of which validation annotation to be executed first, and if it's possible to custom that ? the reason i am asking is that if i left that field empty sometimes the first validation message displayed is for not empty and other times if i left it empty i get the validation message for the length annotation. thanks in advance. Use JSR-303 validation groups. If no groups are specified a constraint is part of the Default Bean