【发布时间】:2016-08-17 17:21:43
【问题描述】:
我在以下位置有 database.properties 文件: grails-app/conf/database.properties
现在我需要读取文件并将其作为属性加载如下:
public static Properties loadProperties(String fileName) {
Properties prop = new Properties();
try {
FileInputStream inputStream = new FileInputStream(fileName);
prop.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}
当我将文件名指定为 database.properties 时,它 显示错误为:java.io.FileNotFoundException: database.properties 在我们跑步的时候。
另一方面,当我将文件名指定为 grails-app/conf/database.properties 它将在本地运行良好。但 当我在 tomcat 服务器中作为 WAR 文件运行时,它将显示与上面相同 错误:java.io.FileNotFoundException:database.properties。
现在我该如何解决上述问题,并且可以在本地和 tomcat 中运行我的代码。
【问题讨论】:
-
这不是 Grails 进行外部化配置的方式。阅读文档:docs.grails.org/latest/guide/conf.html#configExternalized