在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" />