[英]Spring 3.5 Setting an xml property, handling the default value using PropertyPlaceholderConfigurer
I'm working with an old project using Spring 3.5 and xml config.我正在使用 Spring 3.5 和 xml 配置处理一个旧项目。
In the application context I am setting a property to an externally configured xml file value so something like this -在应用程序上下文中,我将一个属性设置为外部配置的 xml 文件值,因此类似于 -
<bean id="myService" class="com.mypath.MyService">
<property name="myProperty" value="${myValue}:myDefaultValue" />
</bean>
This all works properly.这一切正常。
In some tests though there is a test-context.xml coming into play which sets the values of the properties like this在一些测试中,虽然有一个 test-context.xml 开始发挥作用,它设置了这样的属性值
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<util:properties>
<prop key="myProperty">myValue</prop>
</util:properties>
</property>
</bean>
This is failing to 'understand' the default value.这是无法“理解”默认值。 If I leave the value blank I get :myDefaultValue returned.
如果我将值留空,我会得到 :myDefaultValue 返回。 If I set myValue like my example shows I get myValue:myDefaultValue.
如果我像示例所示那样设置 myValue,我会得到 myValue:myDefaultValue。
I had a quick peak at the PropertyPlaceholderConfigurer and it looks very basic without many options.我在 PropertyPlaceholderConfigurer 上有一个快速的峰值,它看起来非常基本,没有很多选项。 I've not used it before.
我以前没用过。 Does anyone know if there is a simple way for me to handle the defaults ?
有谁知道我是否有一种简单的方法来处理默认值? Or maybe I have to use a different method to set the test context values ?
或者我可能必须使用不同的方法来设置测试上下文值?
You have your syntax slightly off.您的语法略有偏差。 The default value for the expression goes inside the braces, like so:
${myValue:defaultValue}
.表达式的默认值位于大括号内,如下所示:
${myValue:defaultValue}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.