use of org.springframework.context.support.ResourceBundleMessageSource in project tutorials by eugenp.
the class ClientWebConfig method messageSource.
@Bean
@Description("Spring message resolver")
public MessageSource messageSource() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
use of org.springframework.context.support.ResourceBundleMessageSource in project irida by phac-nml.
the class ControllerExceptionHandlerTest method testHandleConstraintViolations.
@Test
public void testHandleConstraintViolations() {
final String MESSAGES_BASENAME = "ValidationMessages";
Configuration<?> configuration = Validation.byDefaultProvider().configure();
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(MESSAGES_BASENAME);
configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<?>> constraintViolations = new HashSet<>();
Set<ConstraintViolation<IdentifiableTestEntity>> violations = validator.validate(new IdentifiableTestEntity());
for (ConstraintViolation<IdentifiableTestEntity> v : violations) {
constraintViolations.add(v);
}
ResponseEntity<Map<String, List<String>>> response = controller.handleConstraintViolations(new ConstraintViolationException(constraintViolations));
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
// assertEquals("{\"label\":[\"You must provide a label.\"]}", response.getBody());
Map<String, List<String>> body = response.getBody();
assertTrue("The response must contain an error about a missing label.", body.containsKey("label"));
List<String> labels = body.get("label");
assertEquals("There must only be one error with the label.", 1, labels.size());
String error = labels.get(0);
assertEquals("The error must be 'You must provide a label.'", "You must provide a label.", error);
}
use of org.springframework.context.support.ResourceBundleMessageSource in project irida by phac-nml.
the class IridaApiServicesConfig method validator.
@Bean
public Validator validator() {
ResourceBundleMessageSource validatorMessageSource = new ResourceBundleMessageSource();
validatorMessageSource.setBasename("ValidationMessages");
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setValidationMessageSource(validatorMessageSource);
return validator;
}
use of org.springframework.context.support.ResourceBundleMessageSource in project irida by phac-nml.
the class GalaxyProjectNameTest method setUp.
@Before
public void setUp() {
b = ResourceBundle.getBundle(MESSAGES_BASENAME);
Configuration<?> configuration = Validation.byDefaultProvider().configure();
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(MESSAGES_BASENAME);
configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
ValidatorFactory factory = configuration.buildValidatorFactory();
validator = factory.getValidator();
}
use of org.springframework.context.support.ResourceBundleMessageSource in project PublicCMS-preview by sanluan.
the class ApplicationConfig method messageSource.
/**
* 国际化处理
*
* @return message source
*/
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource bean = new ResourceBundleMessageSource();
bean.setBasenames(StringUtils.split(env.getProperty("cms.language"), ","));
bean.setCacheSeconds(300);
bean.setUseCodeAsDefaultMessage(true);
return bean;
}
Aggregations