Spring 3.1.1 と Hibernate-validator 4.3.0.Final を使用していますが、(クラスパス内の) ValidationMessages から検証メッセージを取得するデフォルトの MessageInterpolator の変更に問題があります。
Spring messageSource からメッセージを取得する ResourceBundleMessageInterpolator を使用したい
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>
ログで Web アプリケーションを起動すると、次のように表示されます。
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 です
後で何かを検証しようとすると、Spring メッセージ ソースからではなく、ValidationMessages.properties からメッセージを取得するだけです。
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.
application-context.xml からわかるように、MessageSourceResourceBundleLocator を使用したいのですが、使用されているため、PlatformResourceBundleLocator の理由がわかりません
何か案は?