有没有办法在Spring XML中指定默认属性值? [英] Is there a way to specify a default property value in Spring XML?

查看:126
本文介绍了有没有办法在Spring XML中指定默认属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 PropertyPlaceholderConfigurer 在Spring配置中使用java属性(此处的详细信息

We are using a PropertyPlaceholderConfigurer to use java properties in our Spring configuration (details here)

例如:

<foo name="port">
  <value>${my.server.port}</value>
</foo>

我们想添加一个额外的属性,但是有一个分布式系统,其中现有实例都可以使用默认值。有没有办法避免更新我们所有的属性文件,通过在没有定义覆盖属性值的情况下指定Spring配置中的默认值?

We would like to add an additional property, but have a distributed system where existing instances could all use a default value. Is there a way to avoid updating all of our properties files, by indicating a default value in the Spring config for when there isn't an overriding property value defined?

推荐答案

您是否正在寻找此处记录的PropertyOverrideConfigurer

Are you looking for the PropertyOverrideConfigurer documented here

http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory -overrideconfigurer


PropertyOverrideConfigurer,
另一个bean工厂后处理器,
类似于
PropertyPlaceholderConfigurer,但在
中与后者形成对比,原始的
定义可以具有默认值,或者
根本没有值用于bean属性。
如果重写的属性文件确实
没有某个bean
属性的条目,则使用默认的上下文
定义。

The PropertyOverrideConfigurer, another bean factory post-processor, is similar to the PropertyPlaceholderConfigurer, but in contrast to the latter, the original definitions can have default values or no values at all for bean properties. If an overriding Properties file does not have an entry for a certain bean property, the default context definition is used.

这篇关于有没有办法在Spring XML中指定默认属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆