1
Spring 3.2.16アプリケーションの環境変数を使用して、ドッカーコンテナ内の設定ファイルを切り替えることを試みています。Docker環境変数のSpringプロパティ
私はプロパティファイルをロードする2つのプロファイル、(100%作品)私は反対devのものを持っている私のアプリケーションのコンテキストで次のようになります。コンテナにアプリケーションをパッケージ化するとき
<beans profile="dev">
<context:property-placeholder location="classpath*:META-INF/spring/dev.properties" />
</beans>
、多くはありませんそれまで、ここで私のドッカーファイルです:
docker run --name='_______' -d -p 8000:8080 --link rabbitmq:rabbitmq -e ENV=test _________________
:
FROM jetty
MAINTAINER Jan Vladimir Mostert "[email protected]"
ADD ./target/ROOT.war /var/lib/jetty/webapps/ROOT.war
EXPOSE 8080
それを実行し、環境変数を設定する-e
旗に気づきます
test
、prod
、...
で実行すると、既定のプロファイルが起動し、cloud
と設定されています。これは、同様に動作します:
<beans profile="cloud">
<context:property-placeholder location="classpath*:META-INF/spring/test.properties" />
</beans>
は、今私はtest.properties
は、環境変数から設定ファイルをピックアップすることをスワップアウトしたいです。
systemProperties
を使用して試してみたが、それは動作しません
:
<beans profile="cloud">
<context:property-placeholder
location="classpath*:META-INF/spring/#{systemProperties['ENV']}.properties" />
</beans>
私は動作しませんsystemEnvironment
を使用して試したいずれか:
<beans profile="cloud">
<context:property-placeholder
location="classpath*:META-INF/spring/#{systemEnvironment['ENV']}.properties" />
</beans>
が入った容器を入力:
docker exec -ti _______ bash
と実行中
echo $ENV
環境変数が正しく設定されているプリント
テスト
、私のapplicationContext.xml
にその変数を得るための正しい方法は何ですか?
これをチェックしてください。http://stackoverflow.com/questions/18744663/how-to-inject-environmental-variables-inside-spring-xml-configuration – 11thdimension
うわー、それはとてもシンプルで、ちょうど '$ {ENV}'とできます。 –