Java 类org.springframework.context.support.ResourceBundleMessageSource 实例源码

项目:lams    文件:LoadedMessageSourceService.java   
@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;
}
   }
项目:spring-i18n-support    文件:PropertiesWriterTest.java   
@Test
public void simpleTest() throws Throwable
{
    try
    {
        String dir = this.getClass().getResource("/").getFile();
        String resource = "writer";
        File dirFile = new File(dir);
        new PropertiesWriter().writePropertiesSet(this.messages(), new Locale("de"), resource, dirFile, "ISO-8859-1");

        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename(resource);
        Assert.assertEquals(FR_TEST, messageSource.getMessage("test.key", null, new Locale("fr")));
        Assert.assertEquals(DE_TEST, messageSource.getMessage("test.key", null, new Locale("de")));
    }
    finally
    {

    }
}
项目:tephra    文件:MessageImpl.java   
@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);
}
项目:spring4-understanding    文件:JstlUtils.java   
/**
 * 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;
}
项目:midpoint    文件:LocalizationServiceImpl.java   
public void init() {
    URL url = buildMidpointHomeLocalizationFolderUrl();
    ClassLoader classLoader = new URLClassLoader(new URL[]{url}, null);

    sources.add(buildSource("Midpoint", classLoader));
    sources.add(buildSource(SchemaConstants.BUNDLE_NAME, classLoader));
    sources.add(buildSource("localization/Midpoint", null));
    sources.add(buildSource(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, null));

    // model security messages as fallback
    ResourceBundleMessageSource modelSecurity = new ResourceBundleMessageSource();
    modelSecurity.setBasename("com.evolveum.midpoint.security");
    sources.add(modelSecurity);

    // spring security messages as a fallback
    ResourceBundleMessageSource springSecurity = new ResourceBundleMessageSource();
    springSecurity.setBasename("org.springframework.security.messages");
    sources.add(springSecurity);
}
项目:spring-component-framework    文件:StaticFeatureResolver.java   
@Override
public void resolve(Component component) {
    if( component.isPlain()) return;
    logger.debug("Resolving {} {} feature", component, getName());
    ApplicationContext parent = resolveContext.getRootContext() ;
    ClassLoader realm = component.getClassLoader();
    //在根据配置的情况下,根据 manifest里面的App-Message加载资源
    String appMessage = getAppMessage(component);
    if(StringUtils.isNotBlank(appMessage)){
        CombinedMessageSource combined  = parent.getBean(CombinedMessageSource.class);
        ResourceBundleMessageSource source = new ResourceBundleMessageSource();
        source.setBundleClassLoader(realm);
        source.setBasenames(StringUtils.split(appMessage, CONFIG_LOCATION_DELIMITERS));
        combined.combine(source);
    }
    resolveContext.registerFeature(component, getName(), realm);
}
项目:class-guard    文件:JstlUtils.java   
/**
 * 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;
}
项目:midpoint    文件:LocalizationServiceImpl.java   
public void init() {
    URL url = buildMidpointHomeLocalizationFolderUrl();
    ClassLoader classLoader = new URLClassLoader(new URL[]{url}, null);

    sources.add(buildSource("Midpoint", classLoader));
    sources.add(buildSource(SchemaConstants.BUNDLE_NAME, classLoader));
    sources.add(buildSource("localization/Midpoint", null));
    sources.add(buildSource(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, null));

    // model security messages as fallback
    ResourceBundleMessageSource modelSecurity = new ResourceBundleMessageSource();
    modelSecurity.setBasename("com.evolveum.midpoint.security");
    sources.add(modelSecurity);

    // spring security messages as a fallback
    ResourceBundleMessageSource springSecurity = new ResourceBundleMessageSource();
    springSecurity.setBasename("org.springframework.security.messages");
    sources.add(springSecurity);
}
项目:molgenis    文件:SpringExceptionHandlerTest.java   
@BeforeClass
public void beforeClass()
{
    AllPropertiesMessageSource molgenisLocalizationMessages = new AllPropertiesMessageSource();
    molgenisLocalizationMessages.addMolgenisNamespaces("web");
    ResourceBundleMessageSource hibernateValidationMessages = new ResourceBundleMessageSource();
    hibernateValidationMessages.addBasenames("org.hibernate.validator.ValidationMessages");
    molgenisLocalizationMessages.setParentMessageSource(hibernateValidationMessages);
    MessageSourceHolder.setMessageSource(molgenisLocalizationMessages);

    globalError = new ObjectError("entityCollectionRequestV2", new String[] { "TwoFieldsSet" }, new Object[] { 1 },
            "must have two fields set");
    fieldError = new FieldError("entityCollectionRequestV2", "num", -10, false,
            new String[] { "Min.entityCollectionRequestV2.num", "Min.num", "Min.int", "Min" }, new Object[] {
            new DefaultMessageSourceResolvable(new String[] { "entityCollectionRequestV2.num", "num" }, null,
                    "num"), 0 }, "must be greater than or equal to 0");
}
项目:scrumtracker2017    文件:ApplicationContext.java   
@Bean
public ResourceBundleMessageSource messageSource()
{
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("locale/messages");
    source.setDefaultEncoding("UTF-8");
    return source;
}
项目:airsonic    文件:CustomThemeSource.java   
@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;
}
项目:nixmash-blog    文件:MailConfig.java   
@Bean
public MessageSource mailMessageSource() {
    ResourceBundleMessageSource msgsource = new ResourceBundleMessageSource();
    if (nixmashModeEnabled)
        msgsource.setBasename("mail-nixmash");
    else
        msgsource.setBasename("mail-messages");
    return msgsource;
}
项目:nixmash-blog    文件:WebConfig.java   
@Bean
public MessageSource messageSource() {
    ResourceBundleMessageSource msgsource = new ResourceBundleMessageSource();
    if (nixmashModeEnabled)
        msgsource.setBasename("nixmash");
    else
        msgsource.setBasename("messages");

    msgsource.setUseCodeAsDefaultMessage(
            Boolean.parseBoolean(environment.getRequiredProperty(USE_CODE_AS_DEFAULT_MESSAGE)));
    return msgsource;
}
项目:xm-ms-entity    文件:LocaleConfiguration.java   
@Bean
public MessageSource defaultMessageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("messages", "i18n/messages");
    messageSource.setDefaultEncoding(Charset.forName("UTF-8").name());
    messageSource.setFallbackToSystemLocale(true);
    messageSource.setCacheSeconds(-1);
    messageSource.setAlwaysUseMessageFormat(false);
    messageSource.setUseCodeAsDefaultMessage(true);
    return messageSource;
}
项目:esup-ecandidat    文件:SpringConfig.java   
/**
 * @return ResourceBundleMessageSource pour les messages de l'application
 */
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setBasenames(
            "i18n/messages",
            "i18n/backoffice/backoffice-messages",
            "i18n/backoffice/nomenclature-messages",
            "i18n/candidat/candidat-messages");
    resourceBundleMessageSource.setFallbackToSystemLocale(false);
    return resourceBundleMessageSource;
}
项目:second-opinion-api    文件:LocalizationConfiguration.java   
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasenames("i18n/messages");
    source.setUseCodeAsDefaultMessage(true);
    source.setDefaultEncoding("UTF-8");
    return source;
}
项目:burstcoin-faucet    文件:BurstcoinFaucet.java   
@Bean
public MessageSource messageSource()
{
  ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
  resourceBundleMessageSource.setDefaultEncoding("UTF-8");
  resourceBundleMessageSource.addBasenames("templates/index");
  return resourceBundleMessageSource;
}
项目:spring-security-angularjs    文件:ServiceConfig.java   
@Bean(name = "messageSource")
public MessageSource getMessageSource() {
    ResourceBundleMessageSource resource = new ResourceBundleMessageSource();
    resource.setBasename("messages");
    resource.setDefaultEncoding("UTF-8");
    return resource;
}
项目:spring4-understanding    文件:ResourceBundleThemeSource.java   
/**
 * 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;
}
项目:cat-boot    文件:ClientEnumControllerTest.java   
@Before
public void before() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("messages");
    messageSource.setDefaultEncoding("UTF8");
    clientEnumController = new ClientEnumController(messageSource);
    clientEnumController.registerClientEnum(Gender.class);
}
项目:petclinic    文件:WebConfig.java   
@Bean
public MessageSource validationMessageSource() {
  ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
  messageSource.setBasenames("validation");
  messageSource.setDefaultEncoding("utf8");
  return messageSource;
}
项目:petclinic    文件:TestUtil.java   
public static Validator createValidator() {
  LocaleContextHolder.setLocale(Locale.ENGLISH);
  ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
  messageSource.setFallbackToSystemLocale(false);
  messageSource.setBasenames("validation");
  messageSource.setDefaultEncoding("utf8");

  LocalValidatorFactoryBean localValidator = new LocalValidatorFactoryBean();
  localValidator.setValidationMessageSource(messageSource);
  localValidator.afterPropertiesSet();
  return localValidator;
}
项目:subsonic    文件:SubsonicThemeSource.java   
@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;
}
项目:spring    文件:ResourceBundleThemeSource.java   
/**
 * 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;
}
项目:java-platform    文件:I18nConfiguration.java   
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
    bundleMessageSource.setUseCodeAsDefaultMessage(true);
    bundleMessageSource.setBasenames(i18nMessages.split(","));
    return bundleMessageSource;
}
项目:coj-web    文件:RestJudgmentsController.java   
private String validateSubmission(SubmissionJudge submit, int lid){
    String errors = null;
    ResourceBundleMessageSource r=new ResourceBundleMessageSource();
    r.setBasename("messages_en");               
    submit.getLanguageIdByKey();        
    try{        
        if (!utilDAO.bool("submit.enabled"))
            return r.getMessage("errormsg.43", null, new Locale("en")).toLowerCase();

        if (!problemDAO.exists(submit.getPid()) || !problemDAO.isEnabled(submit.getPid()))
            return r.getMessage("errormsg.25", null, new Locale("en")).toLowerCase();

        if (problemDAO.isDisable24h(submit.getPid())) 
            return r.getMessage("errormsg.25", null, new Locale("en")).toLowerCase();

        int problemSourceLimit = problemDAO.getSourceLimitByPid(submit.getPid(), lid);

        if (submit.getCode().length() == 0)
            return r.getMessage("errormsg.27", null, new Locale("en")).toLowerCase();

        if (submit.getCode().length() > problemSourceLimit) 
            return r.getMessage("errormsg.28", null, new Locale("en")).toLowerCase();


    }catch(Exception e){
        errors = r.getMessage("errormsg.43", null, new Locale("en")).toLowerCase();
    }
    return errors;
}
项目:coj-web    文件:RestMailController.java   
private String validateEmail(Mail mail) {
    String errors = null;
    ResourceBundleMessageSource r=new ResourceBundleMessageSource();
    r.setBasename("messages_en");
    try {
        if((mail.getTitle() == null || mail.getTitle().length() == 0) && (mail.getContent() == null || mail.getContent().length() == 0)) 
            return r.getMessage("errormsg.39",null, new Locale("en")).toLowerCase();

        if(mail.getUsernameTo().equals("") || mail.getUsernameTo() == null)
            return r.getMessage("errormsg.40",null, new Locale("en")).toLowerCase();

        String[] to = mail.getUsernameTo().split(";");
           if (to.length <= 10) {
            for (String to1 : to) {
                String string = to1.replaceAll(" ", "");
                if (!userDAO.isUser(string)) {
                    return r.getMessage("errormsg.41",null, new Locale("en")).toLowerCase();
                }
            }
            } else 
               return r.getMessage("errormsg.42",null, new Locale("en")).toLowerCase();

            Mail m1 = mailDAO.getMailValues(mail.getId_from());
            int max = m1.getMail_quote();
            int consumed = m1.getConsumed_quote();
            int msgSize = mail.getContent().getBytes().length + mail.getTitle().getBytes().length;
            if (consumed + msgSize > max) 
                return "quote overflow";

            return errors;
    } catch (Exception e) {
        errors = "no valid mail";
    }

    return errors;
}
项目:wte4j    文件:Wte4jConfiguration.java   
@Bean
@Qualifier("wte4j-showcase")
public MessageFactory messageFactoryShowcase() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("org.wte4j.examples.showcase.shared.Messages");
    return new MessageFactoryImpl(messageSource, serviceContext);
}
项目:wte4j    文件:Wte4jAdminConfig.java   
@Bean
@Qualifier("wte4j-admin")
public MessageFactory messageFactory() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("org.wte4j.ui.shared.Messages");
    return new MessageFactoryImpl(messageSource, serviceContext);
}
项目:CoffeeBeansRest    文件:ServicesConfig.java   
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource resource = new ResourceBundleMessageSource();
    resource.setBasename("messages");
    resource.setDefaultEncoding(StandardCharsets.UTF_8.toString());
    return resource;
}
项目:openmrs-module-legacyui    文件:StaticThemeSource.java   
/**
 * @see org.springframework.ui.context.ThemeSource#getTheme(java.lang.String)
 */
@Override
public Theme getTheme(String ignoredArgument) {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(this.themeName);
    return new SimpleTheme(themeName, messageSource);
}
项目:web-harvester    文件:ServiceConfiguration.java   
@Bean public ResourceBundleMessageSource searchOperations() {
    ResourceBundleMessageSource bundle = new ResourceBundleMessageSource();
    bundle.setFallbackToSystemLocale(false);
    bundle.setBasenames("com/jongsoft/harvester/service/operations");
    bundle.setBundleClassLoader(ServiceConfiguration.class.getClassLoader());
    return bundle;
}
项目:coinblesk-server    文件:BeanConfig.java   
@Bean
public MessageSource messageSource() {
    ResourceBundleMessageSource result = new ResourceBundleMessageSource();
    result.setBasename("messages");
    result.setFallbackToSystemLocale(false);
    return result;
}
项目:kaif    文件:MailTestCases.java   
@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);
}
项目:yona-server    文件:ThymeleafConfiguration.java   
@Bean
public ResourceBundleMessageSource smsMessageSource()
{
    final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setFallbackToSystemLocale(false);
    messageSource.setBasename("templates.sms.messages");
    return messageSource;
}
项目:yona-server    文件:ThymeleafConfiguration.java   
@Bean
public ResourceBundleMessageSource emailMessageSource()
{
    final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setFallbackToSystemLocale(false);
    messageSource.setBasename("templates.email.messages");
    return messageSource;
}
项目:editor-de-servicos    文件:WebMVCConfig.java   
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setBasenames("GerenciarUsuarios");
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    return resourceBundleMessageSource;
}
项目:mywx    文件:MvcConfig.java   
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasenames("i18n/message");
    source.setUseCodeAsDefaultMessage(true);
    return source;
}
项目:elasticSearchKata    文件:PropertiesLoader.java   
@Bean  
public  MessageSource messageSource() {  
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();  
    source.setBasename("i18n/messages");  
    source.setUseCodeAsDefaultMessage(true);  
    return source;  
}
项目:midpoint    文件:LocalizationServiceImpl.java   
private ResourceBundleMessageSource buildSource(String basename, ClassLoader classLoader) {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setDefaultEncoding(StandardCharsets.UTF_8.name());
    source.setFallbackToSystemLocale(false);
    source.setBasename(basename);

    if (classLoader == null) {
        classLoader = LocalizationServiceImpl.class.getClassLoader();
    }
    source.setBundleClassLoader(classLoader);

    return source;
}