How to use spring expression to read file content and put it into a string?
I would like to do the following.
For example,
@Value("classpath:myquery.sql")
File f;
@Value("#{org.apache.commons.io.FileUtils.readFileToString(f)}")
String sql;
Or even better
@Value("#{FileUtils.readFileToString(classpath:myquery.sql)}")
String sql;
However, none of above code work.
Just to mention I am using spring version 3.2.0
Thanks.
Finally got the answer myself...
@Value("#{T(org.apache.commons.io.FileUtils).readFileToString(" +
"T(org.springframework.util.ResourceUtils).getFile('classpath:myquery.sql')" +
")}")
String sql;
sql is now default filled by the exact content of myquery.sql under classpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With