首页 > 解决方案 > 从 SpEL 表达式中的 .properties 文件访问属性

问题描述

我需要构建一个动态路径,将属性文件中定义的值与 SpEL 表达式的结果相结合,但找不到正确的语法来实现这一点。

我的情况是这样的:

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:myprop.properties</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="false"/>
</bean>

<bean id="fileNameToFSTree"
    class="foo.bar.FileNameToFSTree"/>

<int-file:outbound-channel-adapter id="filesOut"
    auto-create-directory="true"
    directory-expression="${outDir} + @fileNameToFSTree.nameToTree(payload)"
    delete-source-files="true"/>

鉴于该myprop.properties文件包含一个变量outDir,我想将该变量添加到directory-expression出站文件中。

显然它会定期评估${outDir},但我得到以下异常:

org.springframework.expression.spel.SpelParseException: Expression [/tmp/output + @fileNameToFSTree.nameToTree(payload)] @0: EL1070E: Problem parsing left operand

我在文档或示例中没有发现该案例的痕迹。

有什么提示吗?

标签: xmlspring-integrationspring-el

解决方案


在发布问题后找到这个答案:

Spring 3 表达式语言如何与属性占位符交互?

基本上,语法是:

directory-expression="'${outDir}' + @fileNameToFSTree.nameToTree(payload)"


推荐阅读