Announcement Announcement Module
Collapse
No announcement yet.
Resolver for relative file paths? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolver for relative file paths?

    Hi

    I'm a new Spring user and I'd like to know if there is an helper class to resolve file paths relative to an application context path :
    For example if my application context is located in /home/NoWay/.../WEB-INF/ , I'd like to use something like resolver.resolve("docs/myDoc.txt"); to get the file /home/NoWay/.../Web-INF/docs/MyDoc.txt

    So is there such a class or is it necessary to make it?

    Thank you

    PS : I had a quick look at the API, as far as I know (not to much yet ), it seems that such an helper sould have been an implementation of ApplicationContextAware but didn't find anything...

  • #2
    Have you looked at the Resource infrastructure. There is a ClassPath resolver or FileSystemResource which might be of interest.

    Comment


    • #3
      Thanks for you answer.

      Tell me if i'm wrong but the method getResourceByPath(String) of the class FileSystemResource uses VM working directory as base for the path.

      What I need seems to be the method getResource(String) (inherited), right?

      My main problem is howI have to proceed to make it possible to work.
      I still don't know how Spring is really working and have a lot to learn, (just worked on existing stuff, basicaly a lot of copy/paste to make it work for my java classes without knowing what I was doing ).

      Well so before having a good understanding of Spring, I'd like to make it work
      So will it work if I
      - add a FileSystemResource bean in the application context
      - add my bean with a property referencing the other bean ?

      Thanks

      Comment


      • #4
        OK, didn't realise that FileSystemResourceLoader treats everything as relative

        You could try overloading the FileSystemResourceLoader. Not sure how you would register it into the app context though. Sorry

        Comment

        Working...
        X