How to insert a network file using Spring?
How can I tell the Spring
resource to be a network resource and let it run automatically?
@Value("\\MY-MACHINE\thefile.txt")
private Resource file;
Result:
Caused by: java.io.FileNotFoundException: class path resource [MY-MACHINE\thefile.txt] cannot be resolved to URL because it does not exist
+3
source to share
4 answers
I am assuming your application is deployed on Windows. I don't have a Windows workstation to test it, but as far as I can remember this is:
-
create a symbolic link to your network folder:
mklink /D C:\my-machine \\MY-MACHINE\
-
reference this symlink with an absolute path:
@Value("file:///C:/my-machine/thefile.txt")
private Resource file;
+1
source to share
Accessing a file on a Windows share will not work directly. See connecting to a shared folder in windows with java for more information on how to do this.
0
source to share