Spring 3.1 アプリケーションがあり、コンテキスト ファイルでシステム変数を使用しようとしています。変数「JAVA_MY_ENV」はシステムで定義されています(Windowsでは、コントロールパネルの「システム変数」にあります)。
web.xml では、変数として使用でき、動作します。変数の実際の値 (「electrotype」としましょう) に正常に置き換えられます。
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log/${JAVA_MY_ENV}.log4j.properties</param-value>
</context-param>
メインの「Bean」コンテキストで使用して、インポートを行うこともできます。これも機能します。
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- (...) -->
<import resource="classpath:spring/app-config.xml" />
<import resource="classpath:spring/env/context-env-${JAVA_MY_ENV}.xml" />
</beans>
しかし、私の他のコンテキストファイルの1つである「app-config.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<bean id="appConfiguration" class="com.xxx.app.AppConfiguration">
<constructor-arg value="${JAVA_MY_ENV}" />
</bean>
</beans>
com.xxx.app.AppConfiguration は、解釈された値ではなく、文字列 "${JAVA_MY_ENV}" をコンストラクタ パラメータとして受け取ります。
${} 変数が解釈される場所と解釈されない場所がわかりません。
解釈された ${JAVA_MY_ENV} 値を com.xxx.app.AppConfiguration コンストラクターに渡す方法はありますか?