我的应用程序需要知道可以存储其数据的目录的路径。我尝试设置一个Java系统属性,并将该变量用作Spring XML中的占位符。使用Maven在Spring XML中无法解析系统属性
在Eclipse中,我将该属性添加到我的运行配置的环境中,它工作得很好。 Spring将$ {dataDir}解析为正确的路径。
但是,当我使用Maven2测试应用程序(mvn test -DdataDir = c:/ data)时,Spring抱怨它无法解析占位符。
我的春天XML看起来是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Allows me to use system properties in this file -->
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<bean id="xmlConfiguration" class="org.apache.commons.configuration.XMLConfiguration">
<constructor-arg index="0">
<value>${dataDir}/conf/config.xml</value>
</constructor-arg>
</bean>
</beans>
为什么不说,系统属性传递给春天吗?我究竟做错了什么?感谢您的任何建议!
编辑:当然,你是对的:$ {baseDir}应该是$ {dataDir}。但这只是这个问题的一个错误,而不是真正的代码。
我试图MAVEN_OPTS之前,但要么...
应该是baseDir,而不是数据目录 – toolkit 2009-10-28 15:23:26
工具包,是的,我认为是。 – 2009-10-28 15:35:59