1

我可以做这样的事情:

  <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 也存在那里。谢谢大家。

4

3 回答 3

2

使用 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允许通过命令行覆盖属性。

于 2009-05-01T23:23:34.637 回答
1

使用占位符,例如${magic}并在属性文件中定义键/值以及后处理器。谷歌春季后处理器占位符...

于 2009-05-01T22:12:17.057 回答
0

我看不出你的方式有什么好处。这一切仍然只是配置。

有时人们将数据库连接字符串外部化为 .properties 文件并以这种方式获取它们。我认为这比你的提议更有意义。

于 2009-05-01T22:08:59.590 回答