春天:3.2.0.RELEASE
我打算阅读的文件放在/WEB-INF/resources/test.dat
.
代码如下:
@javax.annotation.Resource(name = "pathMatchingResourcePatternResolver")
private PathMatchingResourcePatternResolver resolver;
...
...
Resource resource2 = resolver.getResource("/WEB-INF/resources/test.dat");
try {
File file = resource2.getFile();
} catch (IOException e) {
e.printStackTrace();
}
从 PathMatchingResourcePatternResolver 的文档中,它描述了:and simple unprefixed paths such as "/WEB-INF/context.xml".
但实际上它会导致一个错误:java.io.FileNotFoundException: class path resource [resources/test.dat] cannot be resolved to URL because it does not exist
。
有谁知道是什么问题?!