Spring MVC ResourceBundleMessageSource XML配置

Spring MVC ResourceBundleMessageSource XML配置,第1张

Spring MVC ResourceBundleMessageSource XML配置

解决方法如下:

package com.mypackage.core.src;import java.io.File;import java.util.ArrayList;import javax.servlet.ServletContext;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.support.ReloadableResourceBundleMessageSource;public class UnderDirectoryReloadableResourceBundleMessageSource extends ReloadableResourceBundleMessageSource {    @Autowired    ServletContext servletContext;    public void setWorkingDirectory(String directoryPath) {        File rootDir = new File( servletContext.getRealPath(directoryPath) );        ArrayList<String> baseNames = new ArrayList<String>();        iterateScanDirectoryAndAddbaseNames(baseNames, rootDir);        setbasenames(baseNames.toArray(new String[baseNames.size()]));    }    private void iterateScanDirectoryAndAddbaseNames(ArrayList<String> baseNames, File directory) {        File[] files = directory.listFiles();        for (File file : files) { if (file.isDirectory()) {     iterateScanDirectoryAndAddbaseNames(baseNames, file); } else {     if (file.getName().endsWith(".properties")) {         String filePath = file.getAbsolutePath().replaceAll("\", "/").replaceAll(".properties$", "");         filePath = filePath.substring(filePath.indexOf("/WEB-INF/"), filePath.length());         baseNames.add(filePath);         System.out.println("Added file to baseNames: " + filePath);     } }        }    }}

XML配置:

<bean id="messageSource" >  <property name="defaultEncoding" value="utf-8" />  <property name="workingDirectory" value="/WEB-INF/webspring/i18n" />  <property name="cacheSeconds" value="3" />  <property name="fallbackToSystemLocale" value="false" /></bean>

享用



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4914981.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存