Reputation: 2100
Is it possible to instantiate a property of type java.io.File
directly in the config?
Something like:
<property><file path="..." /></property>
A possible workaround may be to use a String property and while setting it, create the File instance. Is there a more direct way of achieving this?
Thanks!
Upvotes: 3
Views: 2020
Reputation: 340933
Of course, just define it as <bean/>
with <constructor-arg/>
:
<property>
<bean class="java.io.File">
<constructor-arg value="/foo/bar.txt"/>
</bean>
</property>
Upvotes: 3
Reputation: 884
Yes, you can do this. Simply pass the name of the file as the value of the property:
<bean>
<property name="myFile" value="path-to-file"/>
</bean>
Spring will automatically create an instance of java.io.File for you and inject it into your bean.
Upvotes: 4