You are here

Integrate spring, hiberate-validator for jsr-303 bean validation

on Jun 20, 2012

Official document:
 
http://static.springsource.org/spring/docs/3.1.x/spring-framework-refere...
 
Define spring bean:
 

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource" />
</bean>

This will add spring message source to be recognized by hibernate. Now tell spring this validator will be used in mvc:
 

<mvc:annotation-driven validator="validator"/>

Else spring will create a new default instance for LocalValidationFactoryBean
 
The last step is to add constraints and @Valid on controller, and add error messages.