【发布时间】: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