我创建了一个网络应用程序,并且在已经添加到类路径的单独文件夹中,我有一个属性文件。我正在使用
获取属性对象public static Properties getProps() {
Properties properties = new Properties();
try {
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("mdmdemo.properties"));
} catch (IOException ex) {
Logger.getLogger(BasicUtils.class.getName()).log(Level.SEVERE, null, ex);
}
return properties;
}
拿到 key 没问题。但是,尽管我将属性文件放置在 war 之外,但在构建和部署 war 之前我无法看到 Prop 文件中所做的更改。我还重复创建新的属性对象以查看更改,而不仅仅是在 Web 应用程序初始化中。
我知道,在这种情况下使用数据库是更好的解决方案,但我不允许这样做。
如何获得更改?
最佳答案
缓存可能是 CassLoader 特定的。如果您使用 tomcat,这可能会有所帮助:
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
URL resURL = ctxLoader.getResource(resName);
URLConnection resConn = resURL.openConnection();
resConn.setUseCaches(false);
InputStream resIn = resConn.getInputStream();
关于java - 无需重复构建 Web 应用程序即可获取属性文件中的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29822277/