Java Code Examples for org.springframework.context.support.ResourceBundleMessageSource#setUseCodeAsDefaultMessage()

The following examples show how to use org.springframework.context.support.ResourceBundleMessageSource#setUseCodeAsDefaultMessage() . 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: AbstractControllerTest.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected ExceptionHandlerExceptionResolver createExceptionResolver() {

        final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("rest/messages");
        messageSource.setUseCodeAsDefaultMessage(true);

        ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {

            @Override
            protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
                Method method = new ExceptionHandlerMethodResolver(RestExceptionHandler.class).resolveMethod(exception);
                RestExceptionHandler validationHandler = new RestExceptionHandler();
                validationHandler.setMessageSource(messageSource);
                return new ServletInvocableHandlerMethod(validationHandler, method);
            }
        };

        exceptionResolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        exceptionResolver.afterPropertiesSet();
        return exceptionResolver;
    }
 
Example 2
Source File: WebAppConfig.java    From SA47 with The Unlicense 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource source = new ResourceBundleMessageSource();
	source.setBasename(env.getRequiredProperty("message.source.basename"));
	source.setUseCodeAsDefaultMessage(true);
	source.setDefaultEncoding("UTF-8");
	// # -1 : never reload, 0 always reload
	source.setCacheSeconds(0);
	return source;
}
 
Example 3
Source File: WebAppConfig.java    From SA47 with The Unlicense 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource source = new ResourceBundleMessageSource();
	source.setBasename(env.getRequiredProperty("message.source.basename"));
	source.setUseCodeAsDefaultMessage(true);
	source.setDefaultEncoding("UTF-8");
	// # -1 : never reload, 0 always reload
	source.setCacheSeconds(0);
	return source;
}
 
Example 4
Source File: LocalizationConfiguration.java    From spring-rdbms-cdc-kafka-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Set the source of i18n messages under "resources/i18n/messages_[locale].properties"
 *
 * @return instance of {@link ResourceBundleMessageSource}
 */
@Bean
public ResourceBundleMessageSource messageSource() {
  ResourceBundleMessageSource source = new ResourceBundleMessageSource();
  source.setBasenames("i18n/messages");
  source.setUseCodeAsDefaultMessage(true);
  return source;
}
 
Example 5
Source File: LocalizationConfiguration.java    From spring-rdbms-cdc-kafka-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Set the source of i18n messages under "resources/i18n/messages_[locale].properties"
 *
 * @return instance of {@link ResourceBundleMessageSource}
 */
@Bean
public ResourceBundleMessageSource messageSource() {
  ResourceBundleMessageSource source = new ResourceBundleMessageSource();
  source.setBasenames("i18n/messages");
  source.setUseCodeAsDefaultMessage(true);
  return source;
}
 
Example 6
Source File: I18nConfiguration.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
	bundleMessageSource.setUseCodeAsDefaultMessage(true);
	bundleMessageSource.setBasenames(i18nMessages.split(","));
	return bundleMessageSource;
}
 
Example 7
Source File: ValidationConfiguration.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource edisonValidationMessageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("ValidationMessages");
    source.setUseCodeAsDefaultMessage(true);
    return source;
}
 
Example 8
Source File: ErrorHalRepresentationFactoryTest.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() {
    messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("ValidationMessages");
    messageSource.setUseCodeAsDefaultMessage(true);

}
 
Example 9
Source File: EnumListValidatorTest.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
private EnumListValidator createAndInitializeValidator(boolean ignoreCase, boolean allowNull) {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("ValidationMessages");
    messageSource.setUseCodeAsDefaultMessage(true);

    EnumListValidator enumListValidator = new EnumListValidator(messageSource);
    enumListValidator.initialize(createAnnotation(TestEnum.class, ignoreCase, allowNull));
    return enumListValidator;
}
 
Example 10
Source File: MvcConfig.java    From mywx with Apache License 2.0 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasenames("i18n/message");
    source.setUseCodeAsDefaultMessage(true);
    return source;
}
 
Example 11
Source File: WebConfig.java    From maven-framework-project with MIT License 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource source = new ResourceBundleMessageSource();
	source.setBasename(env.getRequiredProperty("message.source.basename"));
	source.setUseCodeAsDefaultMessage(true);
	return source;
}
 
Example 12
Source File: SpringBundle.java    From data-prep with Apache License 2.0 4 votes vote down vote up
protected SpringBundle(String... baseNames) {
    source = new ResourceBundleMessageSource();
    source.setFallbackToSystemLocale(false);
    source.setBasenames(baseNames);
    source.setUseCodeAsDefaultMessage(true);
}