質問

次のようなことができます:

  <object id="mydb" type="string">
    <value>"blah"</value> <-- note that <value> tag does not really exist
  </object>

後で使用できるように:

  <object id="Someobject" type="Sometype">
    <property name="ConnectionString" ref="mydb"/>
  </object>

編集:これは私が探していたSpringFramework.NETソリューションでした。 PropertyPlaceholderConfigurerもそこに存在するようです。みんなありがとう。

役に立ちましたか?

解決

Springのビルトイン PropertyPlaceholdConfigurer

<bean id="PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
   <property name="location" value="classpath*:/application.properties"/>
</bean>

 <bean id="Someobject" class="somepackage.Sometype">
   <property name="connectionString" value="${mydb}"/>
 </bean>

SYSTEM_PROPERTIES_MODE_OVERRIDE を設定すると、コマンドラインからプロパティを上書きできます。

他のヒント

プレースホルダー(例: $ {magic} )を使用し、PostProcessorとともにプロパティファイルでキー/値を定義します。 Google for springポストプロセッサプレースホルダー ...

あなたのやり方には何の利点もありません。まだすべての設定です。

データベース接続文字列を.propertiesファイルに外部化し、その方法で取得する場合があります。あなたの提案よりも理にかなっていると思います。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top