我将一个具有属性的文件放入 *tomcat_folder*/conf 并尝试读取它:
InputStream input = this.getClass().getClassLoader().getResourceAsStream("conf.properties");
properties.load(input);
但事实上我收到“null”。我尝试打印当前文件夹,它显示“home/username”文件夹(我想从当前文件夹进入conf文件夹)。
“catalina.properties”包含“shared.loader=”,所以理论上这个文件应该从那里读取,但事实并非如此......
有什么解决办法吗?
最佳答案
我找到了解决方案。 我将 ${catalina.home}/conf 添加到 catalina.properties -> shared.loader
shared.loader=${catalina.home}/conf
还有
this.getClass().getClassLoader().getResourceAsStream("conf.properties");
开始正确打开。
关于java - 从Tomcat下的Web应用程序读取conf.properties文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10334456/