hibernate-validator

Autowiring a service into a validator

孤街醉人 提交于 2019-11-28 23:40:09
This example is a bit contrived; I've simplified it to remove extraneous details and to focus on the problem I am having. I have a validator that looks like this: @Component public class UniqueUsernameValidator implements ConstraintValidator<UniqueUsername, String> { @Autowired UsernameService usernameService; @Override public void initialize(UniqueUsername uniqueUsername) { } @Override public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { return !usernameService.exists(s); } } I call the validator from my controller like this: @RequestMapping public void

javax.validation.ValidationException: Unable to find default provider

半腔热情 提交于 2019-11-28 19:10:26
I am currently working on Spring MVC web app and trying to hook up validation using the @Valid annotation. When I fire up the application I'm getting the following exception: javax.validation.ValidationException: Unable to find a default provider I have Hibernate Validator 3.1.0.GA on the classpath as well as javax validation 1.0.0.GA, Hibernate Core 3.3.1.GA and Hibernate Annotations 3.4.0.GA. Is there an incompatiblity in those versions that I'm not seeing, or can anyone think of any reason why I'm still getting this exception with Hibernate Validator on the class path? Cheers, Caps

Hibernate Validator, custom ResourceBundleLocator and Spring

霸气de小男生 提交于 2019-11-28 18:58:17
I'm trying to override default ResourceBundleLocator in hibernate validation 4.1. So far it works perfectly, but the only examples of its usage include java code to instantiate ValidationFactory. When using a web application with spring hibernate validation is automatically configured (only the suitable hibernate validation *.jar file should exist and it is automatically used). How can i substitute ResourceBundleLocator in that scenario? I do not see any way of specyfing my custom ResourceBundleLocator in any properties or applicationContext.xml file. The magic method that does the required

Trouble starting Hibernate Validator due to Bean Validation API

纵然是瞬间 提交于 2019-11-28 09:45:17
I'm trying to use Hibernate Validator in my project, but it isn't working. On the following line: SessionFactory sessions = config.buildSessionFactory(builder.build()); I get the following exception: org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:154) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) at net.myProject.server.util

Use custom validation messages in Hibernate + Spring

大城市里の小女人 提交于 2019-11-28 09:24:38
I tried the steps from the answer here: Hibernate Validator, custom ResourceBundleLocator and Spring But still just getting {location.title.notEmpty} as output instead of the message. dispatcher-servlet.xml <bean name="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="validationMessageSource"> <ref bean="resourceBundleLocator"/> </property> </bean> <bean name="resourceBundleLocator" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>/WEB-INF/validationMessages<

MessageInterpolator in Spring

两盒软妹~` 提交于 2019-11-28 08:48:39
I use Spring 3.1.1 and Hibernate-validator 4.3.0.Final and have a problem with changing default MessageInterpolator, which takes validation messages from ValidationMessages (in classpath). I wanna use ResourceBundleMessageInterpolator which will take messages from my spring messageSource I did something like this in my application-context.xml: <bean id="resourceBundleMessageInterpolator" class="org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator"> <constructor-arg index="0"> <bean class="org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator

Spring Boot - Hibernate custom constraint doesn't inject Service

被刻印的时光 ゝ 提交于 2019-11-28 06:00:30
问题 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

spring validation with @valid where/how custom error messages

不打扰是莪最后的温柔 提交于 2019-11-28 05:35:01
问题 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

Hibernate - Error activating Bean Validation integration

不问归期 提交于 2019-11-28 01:56:22
I am trying to set up Hibernate. But when i try to create my Session Factory, with this code: Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); I get the error: org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:156) at org.hibernate

JSR-303 bean validation with Spring does not kick in

我的梦境 提交于 2019-11-28 01:15:04
问题 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