I use Spring 3.1.1 and Hibernate-validator 4.3.0.Final and have a problem with changing default MessageInterpolator, which takes validation messages from ValidationMessages (in classpath).
I wanna use ResourceBundleMessageInterpolator which will take messages from my spring messageSource
I did something like this in my application-context.xml:
<bean id="resourceBundleMessageInterpolator"
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>
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="messageInterpolator" ref="resourceBundleMessageInterpolator"/>
</bean>
And when I start my web application in logs I see:
11:04:07,402 DEBUG [org.hibernate.validator.internal.engine.ConfigurationImpl] -
Setting custom MessageInterpolator of type
org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator
11:04:07,402 DEBUG [org.hibernate.validator.internal.engine.ConfigurationImpl] -
Setting custom ConstraintValidatorFactory of type org.springframework .validation.beanvalidation.SpringConstraintValidatorFactory
So as you can see, it's not ResourceBundleMessageInterpolator which i want. It's LocaleContextMessageInterpolator
Later when I try to validate something I just get the messages from ValidationMessages.properties, not from spring message source:
11:08:09,397 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] -
ValidationMessages not found.
11:08:09,413 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] -
org.hibernate.validator.ValidationMessages found.
As you can see from application-context.xml I wanna use MessageSourceResourceBundleLocator, but it's used, I don't know why PlatformResourceBundleLocator
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…