2016-08-01 19 views
0

In Spring 4.x verwendete ich immer file:#{systemProperties['user.home']} für den Zugriff auf eine lokale Datei und das Laden von Konfigurationsvariablen. Aber für ein sehr altes Projekt müssen wir Spring 1.x (1.2.7) verwenden, und derselbe Code funktioniert jetzt nicht. Ich habe es auch mit file:${systemProperties['user.home']} versucht, aber nichts. Es scheint mir, dass die Umgebung den Platzhalter nicht lösen kann systemProperties (siehe Abschnitt Fehler zurückgegeben)Zugreifen auf Systemeigenschaften mit Spring 1.x

Kann mir jemand einen Tipp geben?

Anwendungskontext Extrakt

<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> 

Fehler zurückgegeben

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) 

Danke.

Lösung Wie von Jiri Tousek zur Verfügung gestellt:

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

Antwort

1

können Sie PropertyPlaceholderConfigurer verwenden. Es kann Systemeigenschaften unterstützen, siehe #setSystemPropertyMode().

+0

Es funktioniert !!! Vielen Dank!! – gioconno