I'm saving files to a temp directory located outside of my project and I need to be able to link to them after I save them.
I tried adding a resource Handler
registry.addResourceHandler("/photo/**").addResourceLocations("D://photo//");
but it doesn't seem like spring understands that the file isn't on the classpath
21:58:48.293 [http-nio-8080-exec-14] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/photo/a.png] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/D://photo//]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@782ce27b]]] and 1 interceptor
is there a prefix or something I'm missing?
Thanks!
Where is the classpath in spring boot? It's a path inside your project where you place resources. During the build step, Maven will take files in there and place them in the appropriate place for you to use them in your runtime classpath, eg in an executable .
You can define absolute path in resources as given below.
registry.addResourceHandler("/test/**")
.addResourceLocations("file:///Users/testuser/test/");
This example is for *nix, Use proper windows location after file://
Spring resource documentation is provided here
Another personal suggestion: I would try to reduce absolute file dependency as much as possible in any web application. Self contained project will be much more easier in maintenance point of view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With