Hello,
is it possible to inject the content of a file to a setter that expects a string?
Oliver
Hello,
is it possible to inject the content of a file to a setter that expects a string?
Oliver
yes but you have to do somehow the translation. A property editor would work but since there is already one for String the easiest way is to use a FactoryBean:
Even better, you can remove the factory bean with an exiting class and use the factory method instead:<bean ..>
<property name="fileContent">
<bean class="ReadFileFactoryBean">
<property name="file" value="classpath:/some/classpath/to/file"/>
</bean>
</property>
</bean>
<bean ..>
<property name="fileContent">
<bean class="MyFileReader" factory-method="getFileContent">
<constructor value="/path/to/file"/>
</bean>
</property>
</bean>
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Thanks. I thought there must be something that is usable out of the box without writing a custom Factory.Originally Posted by Costin Leau
If you already have a (static) method reading the file contents into a string (quite easy to implement), you can also use MethodInvokingFactoryBean to obtain the string and inject it into a property.
Regards,
Andreas