【发布时间】:2013-08-20 07:58:28
【问题描述】:
我编写自定义消息插值。我希望 JPA 将使用我的自定义消息插值。在这里http://docs.jboss.org/hibernate/validator/4.2/reference/en-US/html/validator-bootstrapping.html#section-message-interpolator我找到了以下描述:
Configuration<?> configuration = Validation.byDefaultProvider().configure();
ValidatorFactory factory = configuration
.messageInterpolator(new ValueFormatterMessageInterpolator(configuration.getDefaultMessageInterpolator()))
.buildValidatorFactory();
Validator validator = factory.getValidator();
但是我应该在哪里写这样的代码?在 init-servlet 的 web.xml 中?我可以在persistance.xml 中提供这样的代码吗?
附:我复制并粘贴代码。在我的情况下
ValueFormatterMessageInterpolator(configuration.getDefaultMessageInterpolator()))
会有这样的变化
CustomMessageInterpolator(configuration.getDefaultMessageInterpolator()))
另见How do I dynamically resolve message parameters with Hibernate Validator?
【问题讨论】:
标签: hibernate validation jpa bean-validation hibernate-validator