添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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!

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.