弹簧表达式读取文件内容 [英] spring expression read file content

查看:89
本文介绍了弹簧表达式读取文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用spring表达式读取文件内容并将其放入字符串中?

How to use spring expression to read file content and put it into a string?

我想执行以下操作.

例如,

@Value("classpath:myquery.sql")
File f;

@Value("#{org.apache.commons.io.FileUtils.readFileToString(f)}")
String sql;

甚至更好

@Value("#{FileUtils.readFileToString(classpath:myquery.sql)}")
String sql;

但是,以上代码均无效.

However, none of above code work.

仅提及我正在使用3.2.0春季版本

Just to mention I am using spring version 3.2.0

谢谢.

推荐答案

最后我自己得到了答案...

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现在默认情况下由classpath下的myquery.sql的确切内容填充

sql is now default filled by the exact content of myquery.sql under classpath

这篇关于弹簧表达式读取文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆