这是使用Guice在Tomcat上运行的webapp.根据文档我们应该能够调用ResourceBundle.clearCache();清除ResourceBundle缓存并可能从bundle属性文件中获取最新信息.
我们还尝试了以下方法:
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”
>将包含“Hello World”的属性文件更改为“Goodbye Earth”
>使用servlet清除缓存
>点击页面,期待看到’Goodbye Earth’
所以问题是,ResourceBundle.clearCache()实际上是如何工作的?还有一些我们需要清除的通用文件缓存吗?