简体   繁体   English

Spring 3.5 设置 xml 属性,使用 PropertyPlaceholderConfigurer 处理默认值

[英]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.

相关问题 Spring PropertyPlaceholderConfigurer默认值覆盖实际属性值 - Spring PropertyPlaceholderConfigurer Default Value overwriting actual property value 设置Spring PropertyPlaceholderConfigurer bean的类路径 - Setting the classpath for a Spring PropertyPlaceholderConfigurer bean 有没有一种方法可以在Spring XML中指定默认属性值? - Is there a way to specify a default property value in Spring XML? Spring MVC表单处理属性值设置错误 - Spring mvc form handling property value setting error Spring PropertyPlaceholderConfigurer注入了错误的值 - Wrong value injected with Spring PropertyPlaceholderConfigurer 春天的多种特性。 PropertyPlaceholderConfigurer类中的属性 - multiple properties in spring. property in PropertyPlaceholderConfigurer class 春季:PropertyPlaceHolderConfigurer递增整数中缀属性名称 - Spring: PropertyPlaceHolderConfigurer incrementing integer infix property name 如何使用PropertyPlaceholderConfigurer使用自定义xml文件将变量加载到我的spring.xml中? - How to use a custom xml file to load variables to my spring.xml using PropertyPlaceholderConfigurer? Maven项目:Spring无法使用PropertyPlaceholderConfigurer在src / main / resources中找到属性文件 - Maven Project: Spring cannot find property file inside src/main/resources using PropertyPlaceholderConfigurer 无法使用PropertyPlaceholderConfigurer在JNDI上下文中找到属性 - Unable to find property in JNDI context using PropertyPlaceholderConfigurer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM