【发布时间】:2013-05-05 01:49:18
【问题描述】:
我在 stackoverflow.com 上阅读过类似的问题,但没有一个解决方案对我有帮助。
我使用的以下配置(maven项目结构):
src/main/resources/properties/app.properties 文件
#possible values: dev test prod
mode: dev
在 Spring 配置中:
<context:property-placeholder location="classpath:properties/app.properties"/>
<import resource="classpath:/spring/db/${mode}-datasource-config.xml"/>
根据${mode}的值我要导入对应的数据源配置文件。
当我使用 mvn clean install tomcat7:run 命令运行嵌入式 tomcat7 时,出现错误:
10, 2013 5:52:29 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /SpringWebFlow threw load() exception
java.lang.IllegalArgumentException: Could not resolve placeholder 'mode' in string value "classpath:/spring/db/${mode}-datasource-config.xml"
target/classes/properties/app.properties 文件存在。
我正在使用 IntelliJ IDEA,在编辑器中我可以单击 <import resource="classpath:/spring/db/${mode}-datasource-config.xml"/> 中的“${mode}”并在属性文件中查看它的值。编辑器本身也将${mode} 更改为灰色的dev,表明它可以识别属性值。在编辑器中我看到:<import resource="classpath:/spring/db/dev-datasource-config.xml"/>
任何想法为什么我会收到错误以及如何解决它?
【问题讨论】:
-
您使用哪个 Spring 版本:=3.1?
-
@Ralph,
3.2.2.RELEASE
标签: java spring maven tomcat properties