java—从spring的applicationcontext.xml中的属性读取

nwo49xxi  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(262)

我希望在applicationcontext.xml中有以下内容

<bean id="foo" class="java.io.File">
        <constructor-arg index="0" value="${FOO}" />
    </bean>

如果我使用以下设置web服务器:

context.setInitParameter("FOO", "the-value");

我会发现我得到了一个 foo 用构造的文件bean the-value .
这似乎没有发生,相反,文件是用 $FOO .
有趣的是,我可以看到spring确实找到了这个属性 FOO 在一段时间内,它的行为就像要使用它,直到它最终调用:org.springframework.beans.propertyeditors.fileeditor.setastext(字符串),它决定了资源不存在。我不明白为什么叫这个我以为这是简单的字符串替换。
我做错什么了吗?不是那样吗 ${FOO} 应该被替换吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题