I18N是Bean验证规范的组成部分。
默认情况下,从名为“
ValidationMessages”的资源包中检索消息。因此,只需为该语言提供此捆绑包(例如ValidationMessages.properties),您就需要覆盖来自Hibernate
Validator的默认消息(从捆绑包“ org.hibernate.validator.ValidationMessages”中检索)。
除了您提到的语言之外,Hibernate Validator
4.2将提供中文(HV-359)和西班牙语(HV-483)消息。
如果您根本不想使用基于文件的资源包,则还可以提供自己的MessageInterpolator或ResourceBundleLocator实现。
使用Hibernate Validator
PlatformResourceBundleLocator,还可以使用具有“
ValidationMessages”以外的名称的捆绑包,如下所示:
Validation .byProvider(Hibernatevalidator.class) .configure() .messageInterpolator( new ResourceBundleMessageInterpolator( new PlatformResourceBundleLocator("com.mycompany.Messages"))) .buildValidatorFactory() .getValidator();`


