Mandroid
Mandroid

Reputation: 7484

Passing path to a file in resources folder to spring bean definition

I have a spring bean definition as:

<bean class="...">
<property name="myFile" value="full\path\to\src\main\resources\a\b\myfile.dat"></property>
</bean>

This works fine. But its full path. I intend it to be like:

value="a\b\myfile.dat"

While trying to do so, I get FilesNotFoundException.

How to do it correctly?

Upvotes: 0

Views: 430

Answers (1)

Alexander Makarov
Alexander Makarov

Reputation: 886

Good day,

You have to read a file through ClassPathResource, here is a good example - https://www.baeldung.com/spring-classpath-file-access

Upvotes: 1

Related Questions