【发布时间】:2014-01-27 15:57:10
【问题描述】:
我需要在启动服务器时加载文件资源。 所以我把文件放在 webapp/WEB-INF 下。
问题在于单元测试失败。
我尝试使用以下方式加载文件:
URL url = Utils.class.getClassLoader().getResource(fileName);
File file = new File(url.getFile());
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
但是类加载器没有找到该文件。它似乎正在寻找它
file:/C:/<local path>/<my project>/target/test-classes/
- 正常模式和测试模式有不同的上下文
我也尝试了here 建议的解决方案,但没有奏效
【问题讨论】:
-
文件是否必须存在于 WEB-INF 中?或者它可以存在于 WEB-INF/classes 中吗?
标签: spring junit resources web-inf