Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File type support in Spring framework

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!

like image 625
Neel Avatar asked Apr 19 '26 11:04

Neel


1 Answers

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.

like image 88
benw Avatar answered Apr 22 '26 02:04

benw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!