我正在尝试通过Spring 3.0为Hibernate Validator 4.1设置自定义消息源.我已经设置了必要的配置:
<!-- JSR-303 -->
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
翻译是从我的消息源提供的,但似乎消息源中的替换令牌在消息源中被查找,即:
my.message=the property {prop} is invalid
Run Code Online (Sandbox Code Playgroud)
有人要求在messageSource中查找"prop".进入ResourceBundleMessageInterpolator.interpolateMessage我注意到javadoc说:
根据JSR 303中指定的算法运行消息插值.
注意:用户捆绑包中的查找是递归的,而默认捆绑包中的查找则不是!
在我看来,对于用户指定的bundle总是会发生递归,所以实际上我无法翻译像Size那样的标准消息.
如何插入我自己的消息源并能够在消息中替换参数?