How to stop DefaultListableBeanFactory from implicitly creating an instance of LocalValidatorFactoryBean

I am using Spring 3.1 and have the following Spring configuration where I explicitly create LocalValidatorFactoryBeanusing my own ValidationMessageSource. I have Hibernate Validator 4.1 in my class path.

<bean id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>ValidatorMsgID</value>
        </list>
    </property>
</bean>

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

<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor"/>

However, I noticed that it was LocalValidatorFactoryBeancreated twice by deleting the debug method in the classes afterPropertiesSet. For the first time for the explicite bean that I defined in the Spring configuration, however, following the fact that the same class is again implicitly repeated by the class DefaultListableBeanFactory- obviously, this time without ValidationMessageSource. Therefore, it seems that when Spring uses LocalValidatorFactoryBeanit, using the one that has Hibernates messagesourceby default, and not the one I specified.

, , , mvc:annotation-driven, config Spring. -

0
1

, , validator "mvc: annotation-driven". spring config

<bean id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>com.mycompany.msgs.ValidatorMsgID</value>
        </list>
    </property>
</bean>

<bean id="validator"
      class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <property name="messageInterpolator">
        <bean class="org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator">
            <constructor-arg index="0">
                <bean class="org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator">
                    <constructor-arg index="0" ref="messageSource"/>
                </bean>
            </constructor-arg>
        </bean>
    </property>
</bean>

<bean class="org.springframework.validation.beanvalidation.MethodValidationPostProcessor">
    <property name="validator" ref="validator"/>
</bean>

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

All Articles