我不想使用ValidationMessages。属性来保存我的应用程序的消息。我想使用其他所有东西使用:LabelNames.properties.
有什么办法吗?
这是可能的。您可以使用ResourceBundleMessageInterpolator
及其bundle定位器API。自定义包名可以像这样指定:
Validator validator =
Validation.byProvider(HibernateValidator.class)
.configure()
.messageInterpolator(
new ResourceBundleMessageInterpolator(
new PlatformResourceBundleLocator( "LabelNames" )))
.buildValidatorFactory()
.getValidator();
使用Spring时,请参考本答案中描述的从LocalValidatorFactoryBean
到MessageSource
的所需包。