2016-04-17 9 views
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旗に気づきます

testprod...で実行すると、既定のプロファイルが起動し、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にその変数を得るための正しい方法は何ですか?

+1

これをチェックしてください。http://stackoverflow.com/questions/18744663/how-to-inject-environmental-variables-inside-spring-xml-configuration – 11thdimension

+0

うわー、それはとてもシンプルで、ちょうど '$ {ENV}'とできます。 –

答えて

1

<beans profile="cloud"> 
    <context:property-placeholder 
     location="classpath*:META-INF/spring/${ENV}.properties" /> 
</beans> 

への切り替えは、魔法、それは動作します。

関連する問題