【问题标题】:Resourcebundle reload with no server restart JSF2 - Jboss 7Resourcebundle 重新加载,无需重新启动服务器 JSF2 - Jboss 7
【发布时间】:2014-03-01 14:13:55
【问题描述】:

我正在尝试在运行时重新加载资源包。 在我的应用程序中,登录后,我得到了调用<f:loadBundle basename="messages" var="msg" /> 的属性。调用是在我的应用程序基础模板中进行的,一切正常。属性文件位于 MyApp/resources/ 下

下一步是尝试更新从我的 userHome/resources 中的属性文件读取的 resourceBundle。我正在调用我的托管 bean 是:

File file = new File(System.getProperty("user.home")+ "/resources/");
    URL[] urls = {file.toURI().toURL()};
    ClassLoader loader = new URLClassLoader(urls);

    ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());  
    ResourceBundle.clearCache();
    bundle = ResourceBundle.getBundle("messages",Locale.ENGLISH, loader);

我没有收到任何错误,并且边界得到了正确的值,但是我的应用程序中发生了任何更改。有人可以告诉我如何重新加载捆绑包并显示我从外部文件中获得的新值??清除缓存似乎不起作用,我摆脱了jsf2的faces-config.xml原因......希望有人能提供帮助。

【问题讨论】:

  • 一件事是以编程方式加载捆绑包。另一件事是在更新它们时让它们保持刷新。我想你的目标是第二个?
  • 是的,我想在每次更改用户/资源下的属性文件时刷新它们

标签: jakarta-ee jsf-2 jboss resourcebundle clear-cache


【解决方案1】:

您可以使用Apache Commons Configuration 解决此问题,

PropertiesConfiguration propertiesConfig = new PropertiesConfiguration("yourProps.properties");
propertiesConfig.setReloadingStrategy(new FileChangedReloadingStrategy());

为此,您需要使用 commons-configuration 依赖项/jar。

<dependency>
    <groupId>commons-configuration</groupId>
    <artifactId>commons-configuration</artifactId>
    <version>20041012.002804</version>
</dependency>

您可以在java-doc 中找到更多详细信息,

资源: hot-reload-of-properties-file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 2010-11-10
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 2017-08-12
    相关资源
    最近更新 更多