我想扩展这个课程:textView.setRotation(-120);
imageView.setRotation(-120);
并覆盖此方法:
org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator
我创建了public String interpolate(String message, Context context, Locale locale) {
...
}
:
MyResourceBundleMessageInterpolator
我也知道我必须在public class MyResourceBundleMessageInterpolator extends ResourceBundleMessageInterpolator {
@Override
public String interpolate(String message, Context context, Locale locale) {
return super.interpolate(message, context, locale);
}
}
对象中注册我的消息插补器:
ValidatorFactory
但问题是我不知道接下来该做什么。如何告诉Hibernate使用这个@Component
public class MyResourceBundleMessageInterpolatorConfigurer extends ResourceBundleMessageInterpolator {
@PostConstruct
public void init() {
ValidatorFactory validatorFactory = Validation.byDefaultProvider()
.configure()
.messageInterpolator(new MyResourceBundleMessageInterpolator())
.buildValidatorFactory();
}
}
对象?
我使用的是Hibernate 4.3.2 + Spring 4.3.13
答案 0 :(得分:0)
您不需要在ValidatorFactory
对象中注册消息插值器。唯一的下一步是覆盖LocalValidatorFactoryBean
类中的默认@Configuration
:
@Configuration
public class MyValidationConfig
{
@Bean
public static LocalValidatorFactoryBean myValidatorFactory ()
{
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
factoryBean.setMessageInterpolator(messageInterpolator());
return factoryBean;
}
private static MessageInterpolator messageInterpolator ()
{
return new MyResourceBundleMessageInterpolator();
}
}