org.hibernate.validator.spi.resourceloading.ResourceBundleLocator#org.hibernate.validator.resourceloading.PlatformResourceBundleLocator源码实例Demo

下面列出了org.hibernate.validator.spi.resourceloading.ResourceBundleLocator#org.hibernate.validator.resourceloading.PlatformResourceBundleLocator 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BlogManagePlatform   文件: ValidationUtil.java
@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();
}
 
源代码2 项目: syndesis   文件: ValidatorContextResolver.java
@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;
}