Java 11 and Spring Boot here. I have the following project directory structure:
myapp/
application.yml
app/
src/
main/
java/
resources/
test/
java/
resources/
smoke/
file1.txt
I have some code:
File resourceFile = org.springframework.util.ResourceUtils.getFile("smoke/file1.txt");
String filePath = resourceFile.getAbsolutePath();
At runtime, filePath
has a value of:
/Users/myuser/workspace/myapp/app/checksum-tests/test-file.txt
When it should be:
/Users/myuser/workspace/myapp/app/src/test/resources/checksum-tests/test-file.txt
Why is this? And more importantly, how can I use ResourceUtils
or something similar in Spring-land to fetch a valid (exists on the file system) File
to a test resource?