在Spring中将默认属性值指定为NULL [英] Specify default property value as NULL in Spring

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

问题描述

我想在Spring XML配置文件中定义默认属性值.我希望此默认值为null.

I want to define default property value in Spring XML configuration file. I want this default value to be null.

类似这样的东西:

...
<ctx:property-placeholder location="file://${configuration.location}" 
                          ignore-unresolvable="true" order="2" 
                          properties-ref="defaultConfiguration"/>

<util:properties id="defaultConfiguration">
    <prop key="email.username" >
        <null />
    </prop>  
    <prop key="email.password">
        <null />
    </prop>  
</util:properties>
...

这不起作用.甚至可以为Spring XML配置中的属性定义null默认值吗?

This doesn't work. Is it even possible to define null default values for properties in Spring XML configuration?

推荐答案

最好以这种方式使用Spring EL

It is better to use Spring EL in such way

<property name="password" value="${email.password:#{null}}"/>

它检查是否指定了email.password,否则将其设置为null(不是"null"字符串)

it checks whether email.password is specified and sets it to null (not "null" String) otherwise

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

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