我不想使用ValidationMessages.properties来存放我的应用程序的消息。我想使用其他所有用途:LabelNames.properties。更改Hibernate Validator的属性文件名
任何可以做到的方式?
我不想使用ValidationMessages.properties来存放我的应用程序的消息。我想使用其他所有用途:LabelNames.properties。更改Hibernate Validator的属性文件名
任何可以做到的方式?
这是可能的。您可以使用ResourceBundleMessageInterpolator
及其捆绑定位器API。
Validator validator =
Validation.byProvider(HibernateValidator.class)
.configure()
.messageInterpolator(
new ResourceBundleMessageInterpolator(
new PlatformResourceBundleLocator("LabelNames")))
.buildValidatorFactory()
.getValidator();
当与弹簧工作,从LocalValidatorFactoryBean
指MessageSource
用于所需束如this answer描述:自定义包名称可以像来指定。
我该把这个放在哪里?我可以把这个放在启动课上,还是我误解了一些东西?我正在使用Spring MVC,所以我不使用Validator对象... – markthegrea