will and way

ただの自分用メモを人に伝える形式で書くことでわかりやすくまとめてるはずのブログ

Propertyファイルを複数選択する

複数読み込み

<!-- プロパティファイル -->
<context:property-placeholder order="1" location="classpath:properties/hogehoge.properties" />
<context:property-placeholder order="2" location="classpath:properties/hugahuga.properties" />

以上のようにして、複数ファイルを定義することが出来る。
hogehoge, hugahuga内に重複があるとSpringでは起動時にエラーになる。
肝はorder

環境変数読み込み

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="searchSystemEnvironment" value="true" />
</bean>
<context:property-placeholder order="1" location="classpath:properties/${ENV_VARIABLE}/hogehoge.properties" />

${}で囲うと、環境変数を読み込んできてくれる。