下面列出了org.hibernate.validator.spi.resourceloading.ResourceBundleLocator#org.hibernate.validator.resourceloading.PlatformResourceBundleLocator 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@PostConstruct
private void init() {
ValidatorProperties properties = ContextUtil.bean(ValidatorProperties.class);
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
//配置hibernate-validator消息插值源
MessageInterpolator interpolator = new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(properties
.getMessageConfigPath()));
configuration.messageInterpolator(interpolator);
//配置快速失败
configuration.failFast(properties.getFailFast());
failFast = properties.getFailFast();
engine = configuration.buildValidatorFactory().getValidator();
}
@Override
public GeneralValidator getContext(final Class<?> type) {
final ResourceBundleLocator resourceBundleLocator = new PlatformResourceBundleLocator("messages");
final MessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator);
final Configuration<?> config = Validation.byDefaultProvider().configure()
.messageInterpolator(messageInterpolator);
final BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
final boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
final Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration
.getDefaultValidatedExecutableTypes();
return new GeneralValidatorImpl(validatorFactory, isExecutableValidationEnabled,
defaultValidatedExecutableTypes);
}
@Bean
public LocalValidatorFactoryBean validator() {
PlatformResourceBundleLocator resourceBundleLocator =
new PlatformResourceBundleLocator(ResourceBundleMessageInterpolator.USER_VALIDATION_MESSAGES, null, true);
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
factoryBean.setMessageInterpolator(new ResourceBundleMessageInterpolator(resourceBundleLocator));
return factoryBean;
}