Announcement Announcement Module
Collapse
No announcement yet.
Loading a file into a String property Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading a file into a String property

    Hello,
    is it possible to specify a file in the classpath and have spring load and inject it into a String in a bean?

    Something like:

    <bean id="a.class" class="AClass">
    <property name="prop" value="classpath*: a-file.xsl"/>
    </bean>

    where prop is a String property of AClass

    Sincerely
    Morten Wilken

  • #2
    NTIKO, but check out the spring "Resource":http://www.springframework.org/docs/.../Resource.html infrastructure

    Comment


    • #3
      actually if you do your own PropertyEditor (see the Spring reference documentation) you can add behavior for reading a file into String. However, a string is a very generic type so using an editor is not a real alternative - you can however, use a custom factoryBean which will load the file and return a string:

      Code:
      ...
      <property name="prop" value-ref="myFileReader"/>
      
      
      ...
      <bean id="myFileReader" class="my.package.MyFileReaderFactoryBean">
        <property name="file" value="classpath*:..."/>
      </bean>

      Comment


      • #4
        i see.

        i will examine these possibilities. thanks for the help.

        sincerely
        Morten wilken

        Comment


        • #5
          If you do decide to go with Costins suggestions; make sure the factory bean accepts a Resource, not a String

          Comment

          Working...
          X