Results 1 to 4 of 4

Thread: Help: Injecting a File to a Spring Bean

  1. #1

    Default 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. #2
    Join Date
    May 2005
    Location
    San Diego, CA
    Posts
    76

    Default

    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

  3. #3
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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.
    Bill

  4. #4

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •