spring expression read file content

前端 未结 2 1588
傲寒
傲寒 2020-12-30 12:13

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         


        
2条回答
  •  梦毁少年i
    2020-12-30 12:40

    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

提交回复
热议问题