org.springframework.context.support.ResourceBundleMessageSource Java Examples

The following examples show how to use org.springframework.context.support.ResourceBundleMessageSource. 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: MessageResourceExtension.java    From Spring-Boot-I18n-Pro with MIT License 6 votes vote down vote up
@PostConstruct
public void init() {
    logger.info("init MessageResourceExtension...");
    if (!StringUtils.isEmpty(baseFolder)) {
        try {
            this.setBasenames(getAllBaseNames(baseFolder));
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
    //设置父MessageSource
    ResourceBundleMessageSource parent = new ResourceBundleMessageSource();
    //是否是多个目录
    if (basename.indexOf(",") > 0) {
        parent.setBasenames(basename.split(","));
    } else {
        parent.setBasename(basename);
    }
    //设置文件编码
    parent.setDefaultEncoding("UTF-8");
    this.setParentMessageSource(parent);
}
 
Example #3
Source File: JstlUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(
		ServletContext servletContext, MessageSource messageSource) {

	if (servletContext != null) {
		String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
		if (jstlInitParam != null) {
			// Create a ResourceBundleMessageSource for the specified resource bundle
			// basename in the JSTL context-param in web.xml, wiring it with the given
			// Spring-defined MessageSource as parent.
			ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
			jstlBundleWrapper.setBasename(jstlInitParam);
			jstlBundleWrapper.setParentMessageSource(messageSource);
			return jstlBundleWrapper;
		}
	}
	return messageSource;
}
 
Example #4
Source File: LoadedMessageSourceService.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
   public MessageSource getMessageService(String messageFilename) {
if (messageFilename != null) {
    MessageSource ms = messageServices.get(messageFilename);
    if (ms == null) {
	ResourceBundleMessageSource rbms = (ResourceBundleMessageSource) beanFactory
		.getBean(LOADED_MESSAGE_SOURCE_BEAN);
	rbms.setBasename(messageFilename);
	messageServices.put(messageFilename, rbms);
	ms = rbms;
    }
    return ms;
} else {
    return null;
}
   }
 
Example #5
Source File: N2oEnvironment.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
public N2oEnvironment() {
    this.metadataRegister = new N2oMetadataRegister();
    this.routeRegister = new N2oRouteRegister();
    this.sourceTypeRegister = new N2oSourceTypeRegister();

    this.messageSource = new MessageSourceAccessor(new ResourceBundleMessageSource());
    this.systemProperties = new N2oWebAppEnvironment();
    this.domainProcessor = new DomainProcessor(new ObjectMapper());
    this.contextProcessor = new ContextProcessor(new TestContextEngine());

    this.namespaceReaderFactory = new ReaderFactoryByMap();
    this.namespacePersisterFactory = new PersisterFactoryByMap();
    this.dynamicMetadataProviderFactory = new N2oDynamicMetadataProviderFactory();
    this.metadataScannerFactory = new N2oMetadataScannerFactory();
    this.sourceLoaderFactory = new N2oSourceLoaderFactory();
    this.sourceValidatorFactory = new N2oSourceValidatorFactory();
    this.sourceCompilerFactory = new N2oSourceCompilerFactory();
    this.compileTransformerFactory = new N2oCompileTransformerFactory();
    this.sourceTransformerFactory = new N2oSourceTransformerFactory();
    this.extensionAttributeMapperFactory = new N2oExtensionAttributeMapperFactory();
    this.sourceMergerFactory = new N2oSourceMergerFactory();
    this.metadataBinderFactory = new N2oMetadataBinderFactory();
    this.pipelineOperationFactory = new N2oPipelineOperationFactory();
    this.buttonGeneratorFactory = new N2oButtonGeneratorFactory();
}
 
Example #6
Source File: MessageImpl.java    From tephra with MIT License 6 votes vote down vote up
@Override
public void onContextRefreshed() {
    Set<String> messages = new HashSet<>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (String beanName : BeanFactory.getBeanNames()) {
        Package beanPackage = BeanFactory.getBeanClass(beanName).getPackage();
        if (beanPackage == null) {
            logger.warn(null, "无法获得Bean[{}]包。", beanName);

            continue;
        }

        String packageName = beanPackage.getName();
        if (resolver.getResource(packageName.replace('.', File.separatorChar) + "/message.properties").exists())
            messages.add(packageName);
    }

    String[] names = new String[messages.size()];
    int i = 0;
    for (String name : messages)
        names[i++] = name + ".message";
    messageSource = new ResourceBundleMessageSource();
    messageSource.setDefaultEncoding(context.getCharset(null));
    messageSource.setBasenames(names);
}
 
Example #7
Source File: DataControllerTestBase.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    SimplePropertyResolver propertyResolver = new SimplePropertyResolver(properties);
    setUpStaticProperties(propertyResolver);
    environment.setSystemProperties(propertyResolver);
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example #8
Source File: CopyValuesControllerTest.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    environment.setSystemProperties(new SimplePropertyResolver(properties));
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example #9
Source File: DefaultValuesControllerTest.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    environment.setSystemProperties(new SimplePropertyResolver(properties));
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example #10
Source File: JstlUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(
		@Nullable ServletContext servletContext, MessageSource messageSource) {

	if (servletContext != null) {
		String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
		if (jstlInitParam != null) {
			// Create a ResourceBundleMessageSource for the specified resource bundle
			// basename in the JSTL context-param in web.xml, wiring it with the given
			// Spring-defined MessageSource as parent.
			ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
			jstlBundleWrapper.setBasename(jstlInitParam);
			jstlBundleWrapper.setParentMessageSource(messageSource);
			return jstlBundleWrapper;
		}
	}
	return messageSource;
}
 
Example #11
Source File: JstlUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(
		ServletContext servletContext, MessageSource messageSource) {

	if (servletContext != null) {
		String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
		if (jstlInitParam != null) {
			// Create a ResourceBundleMessageSource for the specified resource bundle
			// basename in the JSTL context-param in web.xml, wiring it with the given
			// Spring-defined MessageSource as parent.
			ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
			jstlBundleWrapper.setBasename(jstlInitParam);
			jstlBundleWrapper.setParentMessageSource(messageSource);
			return jstlBundleWrapper;
		}
	}
	return messageSource;
}
 
Example #12
Source File: JstlUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(
		@Nullable ServletContext servletContext, MessageSource messageSource) {

	if (servletContext != null) {
		String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
		if (jstlInitParam != null) {
			// Create a ResourceBundleMessageSource for the specified resource bundle
			// basename in the JSTL context-param in web.xml, wiring it with the given
			// Spring-defined MessageSource as parent.
			ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
			jstlBundleWrapper.setBasename(jstlInitParam);
			jstlBundleWrapper.setParentMessageSource(messageSource);
			return jstlBundleWrapper;
		}
	}
	return messageSource;
}
 
Example #13
Source File: LocalizationConfig.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public MessageSource messageSource() {
  LocalizationMessageSource localizationMessageSource =
      new LocalizationMessageSource(
          messageFormatFactory,
          localizationRepository(),
          () -> new Locale(appSettings.getLanguageCode()));
  ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
  resourceBundleMessageSource.addBasenames("org.hibernate.validator.ValidationMessages");
  localizationMessageSource.setParentMessageSource(resourceBundleMessageSource);
  MessageSourceHolder.setMessageSource(localizationMessageSource);
  return localizationMessageSource;
}
 
Example #14
Source File: RestControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeAll
static void beforeClass() {
  DataConverter.setConversionService(new DefaultFormattingConversionService());

  ResourceBundleMessageSource validationMessages = new ResourceBundleMessageSource();
  validationMessages.addBasenames("org.hibernate.validator.ValidationMessages");
  TestAllPropertiesMessageSource messageSource =
      new TestAllPropertiesMessageSource(new MessageFormatFactory());
  messageSource.addMolgenisNamespaces("data", "web");
  messageSource.setParentMessageSource(validationMessages);
  MessageSourceHolder.setMessageSource(messageSource);
}
 
Example #15
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 #16
Source File: CustomThemeSource.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected MessageSource createMessageSource(String basename) {
    ResourceBundleMessageSource messageSource = (ResourceBundleMessageSource) super.createMessageSource(basename);

    // Create parent theme recursively.
    for (Theme theme : settingsService.getAvailableThemes()) {
        if ((basenamePrefix + theme.getId()).equals(basename) && theme.getParent() != null) {
            String parent = basenamePrefix + theme.getParent();
            messageSource.setParentMessageSource(createMessageSource(parent));
            break;
        }
    }
    return messageSource;
}
 
Example #17
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 #18
Source File: ResourceBundleThemeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a MessageSource for the given basename,
 * to be used as MessageSource for the corresponding theme.
 * <p>Default implementation creates a ResourceBundleMessageSource.
 * for the given basename. A subclass could create a specifically
 * configured ReloadableResourceBundleMessageSource, for example.
 * @param basename the basename to create a MessageSource for
 * @return the MessageSource
 * @see org.springframework.context.support.ResourceBundleMessageSource
 * @see org.springframework.context.support.ReloadableResourceBundleMessageSource
 */
protected MessageSource createMessageSource(String basename) {
	ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
	messageSource.setBasename(basename);
	if (this.defaultEncoding != null) {
		messageSource.setDefaultEncoding(this.defaultEncoding);
	}
	if (this.fallbackToSystemLocale != null) {
		messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
	}
	if (this.beanClassLoader != null) {
		messageSource.setBeanClassLoader(this.beanClassLoader);
	}
	return messageSource;
}
 
Example #19
Source File: MailTestCases.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Before
public void mailSetup() {
  configuration = new Configuration(Configuration.VERSION_2_3_21);
  configuration.setDefaultEncoding("UTF-8");
  configuration.setTemplateLoader(new ClassTemplateLoader(MailComposer.class, "/mail"));

  //keep config same as application.yml and WebConfiguration.java
  messageSource = new ResourceBundleMessageSource();
  messageSource.setBasename("i18n/messages");
  messageSource.setDefaultEncoding("UTF-8");
  messageSource.setFallbackToSystemLocale(false);
}
 
Example #20
Source File: FormattersTest.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
@Test
void getFormattedDates() {
    var messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("alfio.i18n.public");
    ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
    ContentLanguage.ALL_LANGUAGES.forEach(cl ->
        FORMATTER_CODES.forEach(code -> Formatters.formatDateForLocale(now, code, messageSource, (a, b) -> {}, cl, true))
    );
}
 
Example #21
Source File: ErrorHalRepresentationFactory.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@Autowired
public ErrorHalRepresentationFactory(
        ResourceBundleMessageSource edisonValidationMessageSource,
        ObjectMapper objectMapper,
        @Value("${edison.validation.error-profile:http://spec.otto.de/profiles/error}") String errorProfile) {
    this.messageSource = edisonValidationMessageSource;
    this.objectMapper = objectMapper;
    this.errorProfile = errorProfile;
}
 
Example #22
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 #23
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 #24
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 #25
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 #26
Source File: ResourceBundleThemeSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a MessageSource for the given basename,
 * to be used as MessageSource for the corresponding theme.
 * <p>Default implementation creates a ResourceBundleMessageSource.
 * for the given basename. A subclass could create a specifically
 * configured ReloadableResourceBundleMessageSource, for example.
 * @param basename the basename to create a MessageSource for
 * @return the MessageSource
 * @see org.springframework.context.support.ResourceBundleMessageSource
 * @see org.springframework.context.support.ReloadableResourceBundleMessageSource
 */
protected MessageSource createMessageSource(String basename) {
	ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
	messageSource.setBasename(basename);
	if (this.defaultEncoding != null) {
		messageSource.setDefaultEncoding(this.defaultEncoding);
	}
	if (this.fallbackToSystemLocale != null) {
		messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
	}
	if (this.beanClassLoader != null) {
		messageSource.setBeanClassLoader(this.beanClassLoader);
	}
	return messageSource;
}
 
Example #27
Source File: DefaultIdentifierNotificationServiceTests.java    From openregistry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
	ms.setBasename("identifier-email-messages");
    this.notificationService = 
    	new DefaultIdentifierNotificationService
    		(mockPersonRepository,
    		new DefaultEmailIdentifierNotificationStrategy(new MockMailSender(), ms),
    		30);
}
 
Example #28
Source File: SubsonicThemeSource.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected MessageSource createMessageSource(String basename) {
    ResourceBundleMessageSource messageSource = (ResourceBundleMessageSource) super.createMessageSource(basename);

    // Create parent theme recursively.
    for (Theme theme : settingsService.getAvailableThemes()) {
        if (basename.equals(basenamePrefix + theme.getId()) && theme.getParent() != null) {
            String parent = basenamePrefix + theme.getParent();
            messageSource.setParentMessageSource(createMessageSource(parent));
            break;
        }
    }
    return messageSource;
}
 
Example #29
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 #30
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}