这是一个使用Guice在Tomcat上运行的webapp。根据文档,我们应该能够调用ResourceBundle.clearCache();
来清除ResourceBundle缓存,并可能从捆绑软件属性文件中获取最新版本。如何清除ResourceBundle缓存
我们也试过如下:
Class klass = ResourceBundle.getBundle("my.bundle").getClass().getSuperclass();
Field field = klass.getDeclaredField("cacheList");
field.setAccessible(true);
ConcurrentHashMap cache = (ConcurrentHashMap) field.get(null);
cache.clear(); // If i debug here I can see the cache is now empty!
和
ResourceBundle.clearCache(this.class.getClassLoader());
行为,我希望是:
- 启动Tomcat和打了一个网页,它说'Hello World'
- 更改属性文件包含'你好世界”到“再见地球
- 清除使用servlet
- 点击的页面,希望看到缓存”再见地球
所以问题是,如何在ResourceBundle.clearCache()实际工作?还有我们需要清除的一些通用文件缓存吗?
你发现了这个解决方案的任何? – prongs 2012-06-13 05:52:59
ResourceBundle.clearCache()在Java 1.6中添加。我正在研究Java 1.4服务器,这就是clearCache()未按预期工作的原因。 – Devrim 2014-11-03 12:16:04