Я использую Spring 3.1.1 и Hibernate -валидатор 4.3.0.Final, и у меня проблема с изменением MessageInterpolator по умолчанию, который принимает сообщения проверки из ValidationMessages (в classpath ).
Я хочу использовать ResourceBundleMessageInterpolator, который будет принимать сообщения из моего spring messageSource
Я сделал что-то подобное в своем приложении -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>
И когда я запускаю свое веб-приложение, в логах я вижу:
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
Итак, как вы можете видеть, это не ResourceBundleMessageInterpolator, который мне нужен. Это LocaleContextMessageInterpolator
Позже, когда я пытаюсь что-то проверить, я просто получаю сообщения из ValidationMessages.properties, а не из источника сообщений Spring :
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.
. Как вы можете видеть из приложения -context.xml, я хочу использовать MessageSourceResourceBundleLocator, но он используется, я не знаю, почему PlatformResourceBundleLocator
Любые идеи?