代码之家  ›  专栏  ›  技术社区  ›  Tommaso Taruffi

Struts 1.2.9重新加载应用程序属性

  •  1
  • Tommaso Taruffi  · 技术社区  · 16 年前

    在我的档案里 配置方法 “我已经写过:

    当我的应用程序成功启动加载时 应用程序属性 .

    我怎样才能 重新加载此属性 (因为我想改变很多写在文件里的属性) 不重新启动应用程序 ?

    谢谢。

    T

    1 回复  |  直到 16 年前
        1
  •  1
  •   stevedbrown    16 年前

    使用(从) http://www.docjar.com/html/api/com/opensymphony/xwork2/util/LocalizedTextUtil.java.html ):

    ...
    clearMap(ResourceBundle.class, null, "cacheList");
    
    // if it's Tomcat
    if ("org.apache.catalina.loader.WebappClassLoader".equals(cl.getName())) {
        clearMap(cl, loader, "resourceEntries");
    }
    ...
    
    private static void clearMap(Class cl, Object obj, String name)
            throws NoSuchFieldException, IllegalAccessException, 
            NoSuchMethodException, InvocationTargetException {
        Field field = cl.getDeclaredField(name);
        field.setAccessible(true);
    
        Object cache = field.get(obj);
    
        synchronized (cache) {
            Class ccl = cache.getClass();
            Method clearMethod = ccl.getMethod("clear");
            clearMethod.invoke(cache);
        }
    }
    

    显然,您可以导入该库并在需要时使用它。