【问题标题】:Accessing system properties with Spring 1.x使用 Spring 1.x 访问系统属性
【发布时间】:2016-08-01 10:58:23
【问题描述】:

在 Spring 4.x 中,我总是使用file:#{systemProperties['user.home']} 来访问本地文件和加载配置变量。但是,对于一个非常古老的项目,我们必须使用 Spring 1.x (1.2.7),而现在相同的代码不起作用。我也试过file:${systemProperties['user.home']},但没有。在我看来,环境无法解析占位符systemProperties(参见错误返回部分)

谁能给我一个提示?

应用程序上下文提取

<bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
            <value>file:{systemProperties['user.home']}/ldap/conf/ldapconfiguration.properties</value>
        </list>
   </property>
   <property name="ignoreResourceNotFound" value="false" />
</bean>

返回错误

Error creating bean with name 'propertyConfigurer' defined in class path resource [ApplicationContext.xml]: Cannot resolve reference to bean 'props' while setting bean property 'properties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'props' defined in class path resource [ApplicationContext.xml]: Initialization of bean failed; nested exception is java.io.FileNotFoundException: ${systemProperties['user.home']}\ldap\conf\ldapconfiguration.properties (The system cannot find the path specified)

谢谢。

解决方案 由 Jiri Tousek 提供:

<bean id="props"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
           <value>file:${user.home}/ldap/conf/ldapconfiguration.properties</value>
        </list>
    </property>
<property name="ignoreResourceNotFound" value="false" />

【问题讨论】:

    标签: spring applicationcontext system-properties


    【解决方案1】:

    您可以使用PropertyPlaceholderConfigurer。可以支持系统属性,见#setSystemPropertyMode()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      相关资源
      最近更新 更多