MessageInterpolator in Spring

两盒软妹~` 提交于 2019-11-28 08:48:39

You don't have to declare ResourceBundleMessageInterpolator and MessageSourceResourceBundleLocator beans by yourself (unless you have to), they are created by LocalValidatorFactoryBean when you supply messageSource:

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

(It does this under the hood:)

public void setValidationMessageSource(MessageSource messageSource) {
    this.messageInterpolator = HibernateValidatorDelegate.buildMessageInterpolator(messageSource);
}

// (...)


private static class HibernateValidatorDelegate {

    public static MessageInterpolator buildMessageInterpolator(MessageSource messageSource) {
        return new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(messageSource));
    }
}

So with simplified bean definition, do you get same debug output? Where do you use "validator" ref? You may have to use <mvc:annotation-driven validator="validator"> for example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!