spring - 在 Spring 中将默认属性值指定为 NULL

标签 spring properties null default-value

我想在 Spring XML 配置文件中定义默认属性值。我希望这个默认值为 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 默认值?

最佳答案

这样使用Spring EL比较好

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

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

关于spring - 在 Spring 中将默认属性值指定为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16735141/

相关文章:

ios - 如果字符串中存在意外字符,NSNumberFormatter 返回 nil

c++ - 一个 nullptr 或 nullptr

java - Autowiring 强类型集合时出现问题

spring - <mvc :default-servlet-handler/>有什么需要和使用

python - 像属性一样访问 dict "values"?

c - 字符串末尾带有垃圾的函数(尝试使用 NULL)

java - Spring Boot RESTful 应用程序错误

java - 如何在 hibernate 4 中定义获取 session 的事务?

python-3.x - 在父类(super class)中缓存属性

c# - 使用动态生成的类型创建通用类的对象