Exemplo n.º 1
0
 @Bean
 public MessageSource messageSource() {
   ReloadableResourceBundleMessageSource ret = new ReloadableResourceBundleMessageSource();
   ret.setBasenames(new String[] {"/resources/messages/messages"});
   ret.setDefaultEncoding("UTF-8");
   return ret;
 }
 /*
  * (non-Javadoc)
  *
  * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
  */
 @Override
 public void afterPropertiesSet() throws Exception {
   Set<String> l = new HashSet<String>();
   String i18nPattern = basePath + "/**/*.properties";
   String i18nFileREG = "(" + StringUtils.join(languages, '|') + ").properties$";
   if (defaultLocale != null) {
     Locale.setDefault(this.defaultLocale);
   }
   try {
     Resource[] resources = applicationContext.getResources(i18nPattern);
     for (Resource resource : resources) {
       String path = resource.getURI().toString();
       if (CapString.checkRegularMatch(path, i18nFileREG)) {
         path =
             path.replaceAll(i18nFileREG, "")
                 .replaceAll(".*/i18n/", "classpath:/i18n/")
                 // for windows
                 .replaceAll(".*\\\\i18n\\\\", "classpath:\\\\i18n\\\\")
                 .replaceAll("\\\\", "/");
         if (!l.contains(path)) {
           l.add(path);
           logger.debug("set message path:" + path);
         }
       }
     }
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   }
   super.setBasenames(l.toArray(new String[l.size()]));
 }
 @Bean
 public ReloadableResourceBundleMessageSource messageSource() {
   ReloadableResourceBundleMessageSource messageSource =
       new ReloadableResourceBundleMessageSource();
   String[] resources = {"classpath:/labels", "classpath:/message"};
   messageSource.setBasenames(resources);
   messageSource.setDefaultEncoding("UTF-8");
   return messageSource;
 }
 @Bean(name = "messageSource")
 public MessageSource getMessageSource() {
   ReloadableResourceBundleMessageSource messageSource =
       new ReloadableResourceBundleMessageSource();
   messageSource.setCacheSeconds(1);
   messageSource.setBasenames("file:./resources/messages");
   messageSource.setDefaultEncoding("UTF-8");
   return messageSource;
 }
Exemplo n.º 5
0
  @Bean(name = "messageSource")
  public MessageSource getMessageSources() {
    ReloadableResourceBundleMessageSource messageSource =
        new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames("/WEB-INF/resources/properties/clientMessages");
    messageSource.setCacheSeconds(0);

    return messageSource;
  }
 /**
  * Override to obtain a local reference to the basenames.
  *
  * @see
  *     org.springframework.context.support.ReloadableResourceBundleMessageSource#setBasenames(java.lang.String[])
  */
 @Override
 public void setBasenames(String[] basenames) {
   super.setBasenames(basenames);
   if (basenames == null) {
     this.basenames = new String[0];
   } else {
     this.basenames = Arrays.copyOf(basenames, basenames.length);
   }
 }
Exemplo n.º 7
0
 protected static void initMessageSourceAccessor() {
   String[] basenames = new String[set.size()];
   set.toArray(basenames);
   ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource =
       new ReloadableResourceBundleMessageSource();
   reloadableResourceBundleMessageSource.setBasenames(basenames);
   reloadableResourceBundleMessageSource.setCacheSeconds(5);
   accessor = new MessageSourceAccessor(reloadableResourceBundleMessageSource);
   messageSource = reloadableResourceBundleMessageSource;
 }
Exemplo n.º 8
0
  @Bean(name = "messageSource")
  public MessageSource messageSource() {

    ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource =
        new ReloadableResourceBundleMessageSource();
    reloadableResourceBundleMessageSource.setBasenames(
        "classpath:META-INF/i18n/holiday", "classpath:ValidationMessages");
    reloadableResourceBundleMessageSource.setDefaultEncoding("UTF-8");
    reloadableResourceBundleMessageSource.setFallbackToSystemLocale(false);
    reloadableResourceBundleMessageSource.setUseCodeAsDefaultMessage(true);
    reloadableResourceBundleMessageSource.setCacheSeconds(5);
    return reloadableResourceBundleMessageSource;
  }
Exemplo n.º 9
0
  @Override
  public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
      throws BeansException {
    URL root = this.getClass().getResource(messageRootPath);
    if (root == null) return;

    File dir = new File(root.getFile());
    List<String> basenames = new ArrayList<String>();
    listFiles(dir, basenames);

    String[] names = new String[0];
    messageSource.setBasenames(basenames.toArray(names));
  }
 @Bean
 public MessageSource messageSource() {
   ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
   ms.setDefaultEncoding("UTF-8");
   ms.setCacheSeconds(600);
   ms.setFallbackToSystemLocale(false);
   ms.setBasenames(
       new String[] {
         "/WEB-INF/i18n/labels",
         "/WEB-INF/i18n/buttons",
         "/WEB-INF/i18n/messages",
         "/WEB-INF/i18n/titles"
       });
   return ms;
 }