سؤال

I am trying to configure Spring : LocalValidatorFactoryBean to set my custom TraversableResolver

I do the following in my applicationContext.xml :

<bean id="customTraversableResolver" class="com.package.core.resolver.SimpleTraversableResolver" />

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

But at runtime, @Valid bean in controller are validated with default traversable resolver (from hibernate validator). So, how to configure default bean validation configuration in spring ?

هل كانت مفيدة؟

المحلول

Have you tried adding validation.xml and adding the traversable resolver configuration in there? Btw, what do you want to achieve with your custom resolver?

نصائح أخرى

While you’re using Spring MVC, you must register your validator in this way:

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

If you want method-level validation, then define bean:

<!-- Enable method-level validation on annotated methods via JSR-303 -->
<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"
      p:validatorFactory-ref="validator" />

Then you don’t need validator.xml anymore.

Note: This works with Spring 3.2.x and Hibernate Validator 4.x.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top