Web MVC应用程序-重新加载属性文件而无需在Java中重新启动服务器

时间:2020-08-25 23:35:09

标签: java java-ee-6 java-ee-8

我有一个Web MVC Java应用程序,想要重新加载@Service类或@Repository类中的属性,而无需重新启动tomcat?有可能吗?

我使用下面的代码重新加载属性,在某些情况下它可以工作,但在@Repository类中不起作用


public class AppProperties {
    private static PropertiesConfiguration configuration = null;
    static {
        try {
            configuration = new PropertiesConfiguration("Path_to_properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
        configuration.setReloadingStrategy(new FileChangedReloadingStrategy());
    }
    public static synchronized String getProperty(final String key) {       
        String prop = (String) configuration.getProperty(key);      
        return prop;
    }
}

0 个答案:

没有答案
相关问题