Issue
Is it possible to load a File/Resource from Maven's test/resources directory using @Value
?
e.g. something like this:
@Value("${test/resources/path/to/file}") File file
EDIT:
@Value("${someFile}") FileSystemResource file;
but at runtime I see that it represents the working directory and not the file that in test/resources
Solution
Anything from test/resources is copied to target/test-classes just before the test phase. Those copied resources will be available on the classpath.
If you start a Spring Configuration in your test classes, there is a binding for classpath resources that allows you to inject them like this:
@Value("classpath:path/to/file")
Resource resourceFile;
It isn't necessary a File, since it could also come from a jar file on the classpath, but you can read it via the InputStream etc.
Answered By - GeertPt
Answer Checked By - Mary Flores (JavaFixing Volunteer)