我有一个属性文件,我现在有这个文件夹中:我应该在哪里放置我的属性文件进行测试?
/src/webapp/WEB-INF/classes/my.properties
我使用加载它:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream is = classLoader.getResourceAsStream("/my.properties");
Properties props = new Properties();
try {
props.load(is);
} catch (IOException e) {
e.printStackTrace();
}
String test = props.getProperty("test");
现在能正常工作在我的Spring MVC应用程序。
但是当我为此创建一个测试时,它失败了,我假设因为应用程序加载它的方式不使用web-inf/classes,因为它只是一个类而不是弹簧web应用程序。
那么,我把我的属性文件,以便当我的junit测试运行时,属性文件被拾起?
此外,对于我的web应用程序,除了/ web-inf/classes之外,还有哪些其他文件夹位于默认类路径中?
我相信你的路径是:'/ src目录/ web应用/ WEB-INF /班/ my.properties' – 2012-03-17 14:38:46