Announcement Announcement Module
Collapse
No announcement yet.
Help: Injecting a File to a Spring Bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help: Injecting a File to a Spring Bean

    Hi sorry if this has been answered before but I can't find the solution anywhere. I wondering what the best way to inject a java.io.File object into a bean. The file is actually going to be an MS-Word document template so I'm not talking about a spring config file or property file, basically a file I read as a byte array.

    Just wondeing the best way to go about this in a web app as I know there's sometimes issues reading a file resource via the ServletContext.

    Thx in advance,

    Dave.

  • #2
    You could inject it as a spring resource and then do a getFile() on the resource. Check out http://static.springframework.org/sp...resources.html

    Comment


    • #3
      You can also have your setter/constructor take a java.io.File. Spring knows how to convert from a file system or classpath reference into a File. You should be able to use the level of abstraction which suits your situation.

      Comment


      • #4
        You can also have your setter/constructor take a java.io.File. Spring knows how to convert from a file system or classpath reference into a File. You should be able to use the level of abstraction which suits your situation.
        Is it possible to do this with the @Resource annotation?

        Comment

        Working...
        X