1.简介
使用EhCache缓存资源,使用ResourcePatternResolver从多个文件中加载资源
2.源文件
1)EhCacheResourceBundles
package com.siyuan.test.spring; import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Properties; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import net.sf.ehcache.CacheManager; public class EhCacheResourceBundles { private static final Logger LOGGER = LoggerFactory.getLogger(EhCacheResourceBundles.class); private static final String RESOURCE_FILE_SUFFIX = ".properties"; private CacheManager cacheManager; private Map<Locale, EhCacheResourceBundle> resourceBundles = new HashMap<Locale, EhCacheResourceBundle>(); /** * EhCache configuration location * Spring Resource path, a absolute path, * Used to configure the EhCache */ public EhCacheResourceBundles(String configuration, String resourcePatterns) throws IOException { if (StringUtils.isBlank(configuration)) { throw new IllegalArgumentException( "argument[configuration] can not be blank"); } if (StringUtils.isBlank(resourcePatterns)) { throw new IllegalArgumentException( "argument[resourcePatterns] can not be blank"); } initCacheManager(configuration); initResourceBundles(resourcePatterns); } private void initCacheManager(String configuration) throws IOException { ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); Resource[] resources = resourceResolver.getResources(configuration); if (resources.length == 0) { throw new IllegalArgumentException("configuration[" + configuration +"] can not be resolved to a resource"); } InputStream input = null; try { LOGGER.info("init CacheManager by the configuration[{}] ", resources[0]); input = resources[0].getInputStream(); cacheManager = CacheManager.newInstance(input); } finally { if (input != null) { input.close(); } } } private void initResourceBundles(String resourcePatterns) throws IOException { LOGGER.info("load resource from [{}]", resourcePatterns); ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); String[] resourcePatternArray = resourcePatterns.split(","); for (String resourcePattern : resourcePatternArray) { LOGGER.info("load resource from [{}]", resourcePattern); Resource[] resources = resourceResolver.getResources(resourcePattern); for (Resource resource : resources) { loadResource(resource); } } } private void loadResource(Resource resource) throws IOException { String fileName = resource.getFilename(); if (!fileName.endsWith(RESOURCE_FILE_SUFFIX)) { LOGGER.warn("file[{}] does not ended with [{}], will be omitted", resource, RESOURCE_FILE_SUFFIX); return; } InputStream input = null; try { // Locale locale = getLocale(fileName); if (locale == null) { LOGGER.warn("can not resolve locale from file[{}] by name, " + "and the file will be omitted, please make the file name " + "match XXX_xx.properties or XXX_xx_XX.properties pattern", fileName); return; } EhCacheResourceBundle resourceBundle = resourceBundles.get(locale); if (resourceBundle == null) { LOGGER.debug("no EhCacheResourceBundle is corresponding to the " + "locale[{}], will create one", locale); cacheManager.addCache(locale.toString()); resourceBundle = new EhCacheResourceBundle( cacheManager.getCache(locale.toString())); resourceBundles.put(locale, resourceBundle); } input = resource.getInputStream(); Properties properties = new Properties(); properties.load(input); LOGGER.info("load messages from [{}]", resource); for (Object key : properties.keySet()) { resourceBundle.addMessage((String) key, properties.getProperty((String) key)); } } finally { if (input != null) { input.close(); } } } private Locale getLocale(String fileFullName) { Locale locale = null; String fileName = fileFullName.substring(0, fileFullName.lastIndexOf(RESOURCE_FILE_SUFFIX)); String[] fileInfos = fileName.split("_"); if (fileInfos.length == 2) { locale = new Locale(fileInfos[1]); } else if (fileInfos.length == 3) { locale = new Locale(fileInfos[1], fileInfos[2]); } LOGGER.debug("locale[{}] is resolved from the fileName[{}]", locale, fileFullName); return locale; } public String getMessage(String key, Locale locale) { EhCacheResourceBundle resourceBundle = resourceBundles.get(locale); if (resourceBundle == null) { LOGGER.warn("no EhCacheResourceBundle is corresponding to the " + "locale[{}]", locale); return null; } return resourceBundle.getString(key); } public String getMessage(String key, Locale locale, Object...arguments) { String messageFmt = getMessage(key, locale); if (messageFmt == null) { return null; } return new MessageFormat(messageFmt).format(arguments); } }
2)EhCacheResourceBundle
package com.siyuan.test.spring; import java.util.Enumeration; import java.util.ResourceBundle; import net.sf.ehcache.Cache; import net.sf.ehcache.Element; public class EhCacheResourceBundle extends ResourceBundle { private Cache cache; public EhCacheResourceBundle(Cache cache) { this.cache = cache; } public void addMessage(String key, String value) { cache.put(new Element(key, value)); } @Override protected Object handleGetObject(String key) { Element value = cache.get(key); if (key == null) { return null; } return value.getObjectValue(); } @Override public Enumeration<String> getKeys() { throw new UnsupportedOperationException( "EhCacheResourceBundle does not support enumerating its keys"); } }
3)ehcache-i18n.xml
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false" monitoring="autodetect" dynamicConfig="true"> <defaultCache eternal="true" maxEntriesLocalHeap="0" /> </ehcache>
4)资源文件
|-i18n
|-en_US
|-folder
|-test_en_US.properties
test.key1=test.key1.en_US {0}
|-test_en_US.properties
test.key=test.key.en_US
|-zh
|-folder
|-test_zh.properties
test.key1=test.key1.zh {0}
|-test_zh.properties
test.key=test.key.zh
5)EhCacheResourceBundlesTest
import java.io.IOException; import java.util.Locale; import com.siyuan.test.spring.EhCacheResourceBundles; public class EhCacheResourceBundlesTest { public static void main(String[] args) throws IOException { EhCacheResourceBundles resourceBundles = new EhCacheResourceBundles("classpath:ehcache-i18n.xml", "classpath*:i18n/**/*.properties"); System.out.println(resourceBundles.getMessage("test.key", new Locale("zh"))); System.out.println(resourceBundles.getMessage("test.key", new Locale("en", "US"))); System.out.println(resourceBundles.getMessage("test.key1", new Locale("zh"), "test zh")); System.out.println(resourceBundles.getMessage("test.key1", new Locale("en", "US"), "test en_US")); } }
运行结果
test.key.zh test.key.en_US test.key1.zh test zh test.key1.en_US test en_US
3.附件
程序源代码
相关推荐
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
使用opencv决策树训练mushroom数据集-python源码.zip
基于Faster RCNN的人脸检测识别系统python源码+项目说明+wider_face数据集.zip ### 三,使用说明 1. 锚框的大小为[128、256、512],比率为[1:1、1:2、2:1]。 2. tensorflow的版本是'1.9.0',keras的版本是'2.1.5',除了使用tensorflow2.0之后版本,其他版本都可以尝试。不支持python2.x。 3. 使用的是tensorflow backend,theano可以自行修改。 4. wider face的Label文件格式与VOC2012的label不同,而我使用的Faster RCNN需要VOC2012的格式,所以需要将label文件转换一下格式。具体可以查看 [https://blog.csdn.net/qq_37431083/article/details/102742322](https://blog.csdn.net/qq_37431083/article/details/102742322) 5. 在训练过程中可能会出现`"ValueError: 'a' cannot be empty
1985-2022年广东省企业专利明细数据-专利名称专利类型专利摘要专利授权专利 分类号等 1、数据说明: 在知识经济时代,技术创新是实现经济内生增长的关键动力, 科技优势成为经济竞争优势的根本源泉。新一轮科技革命和产业变革加速,全球创新速度加 快,我国正在经历发展方式转变、经济结构优化、新旧动能转换的攻关期,创新日益成为破 解发展难题的关键。专利作为技术与知识的载体,其申请数量是创新研究中衡量创新最常用 的指标之一,中国成为创新领先国家也同样体现在专利申请量上。改革开放 40 年来, 我们的知识产权事业取得了举世瞩目的巨大成功,但也面临着“大而不强”的问题。引导专 利从追求数量向提高质量转变,这是国家近几年的政策扶持重点,也是未来专利申请审查的 一个风向标,针对海量专利数据的价值识别与预测,逐渐成为当前的研究热点。 本数据提 供了1985-2022年广东省的企业专利明细数据,可用于各类专利相关研究。 2、 数据来源: 数据来源为国家知识产权局,利用知识产权局的高级检索,选择地区、年份、 专利类型,对全国31省的各类专利进行统计并将检索结果整理为面板数据,包括发明公开 、发明授权、实用
Kaggle竞赛 稻田病害分类-python源码.zip
文件目录解释 # 1. Models 用来存放的模型,可以是已有的Paddle格式的模型 # 2. Pages - assets 用到的图片资源 - assets.qrc 使用PySide生成的样式文件 - assets_rc.py GUI界面的样式文件,此目录和根目录都有,我忘记是调用的哪一个了,所以都保留了。 # 3. Utils - AttResNet.py 网络代码 - DatasetProcess.py 数据集处理代码 - FaceDetection.py 人脸检测代码 - Predict.py 模型预测代码 - VisualTrain.py 模型训练代码 - CSV文件 用来保存数据集和创建的信息 # 4. Dataset 存放数据集的目录 注意事项 * # 配置好环境,安装使用PySide的工具,不会安装见如下以PyCharm为例的说明 1. 依次点击 File:arrow_right:Settings:arrow_right:Tools:arrow_right:External Tools:arrow_right::heavy_plus_sign:添加PySide工具,
机械设计小线圈生产打蜡机sw20非常好的设计图纸100%好用.zip
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
基于普中51开发板的超声波测距+蜂鸣器报警 (附开发板原理图) 基于普中51开发板的超声波测距+蜂鸣器报警 (附开发板原理图)
机械设计大倾角输送机sw17非常好的设计图纸100%好用.zip
每个压缩包都附有数据表和数据来源 信心指数 1.投资者信心指数表 数据区间:20 08.04-2022.09,月度数据(数据库中该项数据的全部内容) 字段设置:全 选 全部字段: DeclareDate [发布日期] - YYYY-MM-DD SgnMonth [统计月度] - YYYY-MM IndexCode [指数编 码] - Q4001信心指数;Q4002国内经济基本面;Q4003国内经济政策; Q4004国际经济金融环境;Q4005股票估值;Q4006大盘乐观;Q4007大 盘反弹;Q4008大盘抗跌;Q4009买入; Name [指数名称] - 信心指 数;国内经济基本面;国内经济政策;国际经济金融环境;股票估值;大盘乐观;大盘反弹 ;大盘抗跌;买入; Value [当月值] - LastValue [上月值] - Mom [环比增减] - 压缩包所含文件: 数据样例: 2.消费者信心指数表 数据区间:1999.01-2022.09,月度数据(数据库中该项数据的全部内容 ) 字段设置:全选 全部字段: SgnMonth [统计月度] - YYYY-M M Expect
使用Keras+TensorFlow进行目标检测-python源码.zip
Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板
lda代码-checkpoint-checkpoint.ipynb
变量如下: Ctnb[城市编号]-城市编号 Prvn[所属省份]-城市所属的省份 Pftn[所属地级市]-城市所属的地级市 Ctn[城市名称]-城市名称 Dat e[日期]-天气数据发布的时间 Dywek[星期时间]-星期时间 Htmpt[最 高气温]-当天天气最高气温,单位:℃ Ltmpt[最低气温]-当天天气最低气温, 单位:℃ Wthcdt[天气情况]-当天天气的具体状况 Wnddrt[风向]-当 天天气风吹来的方向 Wndfrc[风力]-当天天气风力级别 数据展示:
触屏版自适应手机wap软件网站模板 触屏版自适应手机wap软件网站模板