【问题标题】:Allowing $ character in a property file managed by PropertyPlaceholderConfigurer允许在 PropertyPlaceholderConfigurer 管理的属性文件中使用 $ 字符
【发布时间】:2013-04-08 09:29:07
【问题描述】:

我有一个名为setting.properties的属性文件,内容如下:

authentication.provider=${Home_Url}/idm/names.lst

我正在通过Spring 框架内的PropertyPlaceholderConfigurer 使用此文件,如下所示:

<bean id="acl.authentication.provider" class="java.lang.String">
    <constructor-arg index="0" value="${authentication.provider}"/>
</bean>

但是当我初始化上述上下文时,我收到以下错误:

线程“主”org.springframework.beans.factory.BeanDefinitionStoreException 中的异常:
在类路径资源 [context.xml] 中定义的名称为“acl.authentication.provider#0”的无效 bean 定义:无法解析占位符“Home_Url”

我的问题是:当属性文件中的值要使用 PropertyPlaceholderConfigurer 进行处理时,有没有办法可以包含 $ 字符?

【问题讨论】:

    标签: java spring properties


    【解决方案1】:

    最简单的解决方法是将PropertyPlaceholderConfigurer 配置为将其ignoreUnresolvablePlaceholders 属性设置为true,这将导致它忽略它无法解决的plcaeholders,而不是因为异常而失败。或者,将placeholderPrefix 更改为其他内容,例如@{,然后使用

    <constructor-arg index="0" value="@{authentication.provider}"/>
    

    【讨论】:

      猜你喜欢
      • 2013-06-30
      • 2021-05-13
      • 2013-11-15
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 2015-07-18
      相关资源
      最近更新 更多