Java Code Examples for org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#setMessageInterpolator()

The following examples show how to use org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#setMessageInterpolator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidatorTests.java    From spring-graalvm-native with Apache License 2.0 5 votes vote down vote up
private Validator createValidator() {
	LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
	localValidatorFactoryBean
			.setMessageInterpolator(new MessageInterpolatorFactory().getObject());
	localValidatorFactoryBean.afterPropertiesSet();
	return localValidatorFactoryBean;
}
 
Example 2
Source File: ConfigurationServiceTests.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
LocalValidatorFactoryBean getValidator() {
	GenericApplicationContext context = new GenericApplicationContext();
	context.refresh();
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setApplicationContext(context);
	validator.setMessageInterpolator(new MessageInterpolatorFactory().getObject());
	validator.afterPropertiesSet();
	return validator;
}
 
Example 3
Source File: ValidationConfiguration.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: DefaultValidatorConfiguration.java    From cm_ext with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the validator factory bean that Spring uses to
 * construct a Validator.
 *
 * @return a Validator Factory Bean
 */
@Bean
public LocalValidatorFactoryBean validatorFactoryBean() {
  BeanConstraintValidatorFactory validatorFactory = ctx.getBean(BeanConstraintValidatorFactory.class);
  MessageInterpolator messageInterpolator = ctx.getBean(MessageInterpolator.class);
  LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
  factoryBean.setMessageInterpolator(messageInterpolator);
  factoryBean.setConstraintValidatorFactory(validatorFactory);
  return factoryBean;
}
 
Example 5
Source File: SpringTestConfig.java    From super-csv-annotation with Apache License 2.0 5 votes vote down vote up
@Bean
@Description("Spring用のBeanValidatorのValidatorの定義")
public Validator csvLocalValidatorFactoryBean() {
    
    LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
    
    // メッセージなどをカスタマイズ
    validator.setMessageInterpolator(new MessageInterpolatorAdapter(
            springMessageResolver(), new MessageInterpolator()));
    return validator;
}