6

ユーザーごとに異なるプロパティ セットを用意すると便利です。

<?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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:property-placeholder
        location="classpath:/path/to/package/default.properties,
        classpath:/path/to/package/#{ systemProperties['user.name'] }.properties"/>

</beans>

アプリケーションを実行すると、Spring は式を認識しません。コンテキストは開始されず、Spring は次のように言います。class path resource [path/to/package/#{ systemProperties['user.name'] }.properties] cannot be opened

式を手動で文字列に置き換えて有効なリソースにすると、動作は期待どおりになります。マニュアルには、それが機能するはずであると記載されています。

spring-context と spring-core (3.1.2-RELEASE) はクラスパスにあります。

  • なぜ春は環境変数を取得しないのですか?
  • 私は、同じ機能上の問題を解決する代替ソリューションを受け入れます。
4

2 に答える 2

4

SpEL式はそこでは許可されていません。ただし、間接的にやりたいことができます...

<context:property-placeholder properties-ref="props"/>

<util:properties id="props" location="classpath:#{systemProperties['foo']}"/>
于 2012-11-02T18:18:52.980 に答える
0

これが質問に対する完全な答えです。既定のプロパティに対するユーザー プロパティのオーバーライドを保持します。受け入れられた回答の編集が拒否されました。

<context:property-placeholder properties-ref="springContextCongifurationProperties"
                              location="classpath:/path/to/package/default.properties"
                              local-override="true"/>

<util:properties id="springContextCongifurationProperties"
                 location="classpath:/path/to/package/#{ systemProperties['user.name'] }.properties"/>
于 2012-11-03T09:55:10.943 に答える