문제

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