I tried implementing validation for my web application like described in section 5.7.4.3 of the Spring 3.0 documentation:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="validator">
<bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
</property>
</bean>
</property>
</bean>
I've added hibernate-validator as a dependency and everything looks OK, but starting my web app results in the following error:
org.springframework.beans.NotWritablePropertyException:
Invalid property 'validator' of bean class
[org.springframework.web.bind.support.ConfigurableWebBindingInitializer]:
Bean property 'validator' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
When looking at the API it's pretty obvious that something's wrong. LocalValidatorFactoryBean
implements javax.validation.Validator
while ConfigurableWebBindingInitializer.setValidator()
expects a org.springframework.validation.Validator
.
Any solution for this?
EDIT
About LocalValidatorFactoryBean
:
This is the central class for
javax.validation
(JSR-303) setup in a Spring application context: It bootstraps ajavax.validation.ValidationFactory
and exposes it through the SpringValidator
interface as well as through the JSR-303Validator
interface and theValidatorFactory
interface itself.
Like Alex Marshall stated below this is not the case. LocalValidatorFactoryBean
only implements javax.validation.Validator
.
LocalValidatorFactoryBean
does extend SpringValidatorAdapter
though, which implements org.springframework.validation.Validator
.