Q:

How to read file in /WEB-INF/, but not in classes folder by using PathMatchingResourcePatternResolver within SpringMVC?

Spring: 3.2.0.RELEASE
The file i intended to read is placed at /WEB-INF/resources/test.dat.
Code as below:
 @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();
    }

From doc of PathMatchingResourcePatternResolver, it described: and simple unprefixed paths such as "/WEB-INF/context.xml".
But actually it cause an error that : java.io.FileNotFoundException: class path resource [resources/test.dat] cannot be resolved to URL because it does not exist.
Does anyone know what the problem is?!

A:

If it's a maven project. Instead of having this file in /WEB-INF/resource folder, put it into /src/main/resources folder. Resources in this folder are added to classpath. 
So you can use something like  : 
Thread.currentThread().getContextClassLoader().getResourceAsStream("test.dat");

This will work.

