私のアプリケーションは、データを保存できるディレクトリへのパスを知る必要があります。Java システム プロパティを設定し、その変数を Spring XML のプレースホルダーとして使用しようとしました。
Eclipse で、そのプロパティを実行構成の環境に追加したところ、問題なく動作しました。Spring は${dataDir}を正しいパスに解決します。
しかし、Maven2 ( mvn test -DdataDir=c:/data ) を使用してアプリケーションをテストすると、Spring はプレースホルダーを解決できないと文句を言います。
私の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>
そのシステム プロパティが Spring に渡されないのはなぜですか? 私は何を間違っていますか?ご提案ありがとうございます。
編集:もちろん、その通りです: ${baseDir} は ${dataDir} である必要があります。しかし、それはこの質問の単なるタイプミスであり、実際のコードではありません。
以前にMAVEN_OPTSを試しましたが、どちらも機能しません...