Lesen Sie eine Umgebungsvariable aus applicationContext.xml

Ich muss eine in meiner web.xml definierte Umgebungsvariable lesen

<env-entry>
    <description>Path Repositorio NFS</description>
    <env-entry-name>PATH_ENV</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>C:/V3</env-entry-value>
</env-entry>

Von meinemapplicationContext.xml

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="${PATH_ENV}/myprop.properties" />
</bean>

Wie kann ich das machen ?

Endlich habe ich das nächste gemacht:

1 Definieren Sie die Umgebungsvariable in context.xml:

<Environment name="PATH_ENV" type="java.lang.String"/>

2 Definieren Sie env-entry in web.xml

<env-entry>
    <description>Path Repositorio NFS</description>
    <env-entry-name>PATH_ENV</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>/WEB-INF/</env-entry-value>
  </env-entry>

3 Definieren Sie in applicationContext.xml

<bean id="configurationPath" class="org.springframework.jndi.JndiObjectFactoryBean">  
    <property name="jndiName">  
        <value>java:comp/env/PATH_ENV</value>  
    </property>  
</bean>  

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location">
            <bean factory-bean="configurationPath" factory-method="concat">
                <constructor-arg value="myprop.properties"/>
            </bean>
        </property>
    </bean>

Dies wird korrekt ausgeführt. Wenn ich jedoch einen vollständigen Pfad definiere in:

<env-entry-value>C:/V3/</env-entry-value>

Ich habe das nächste Problem:

java.io.FileNotFoundException: Could not open ServletContext resource [/C:/V3/aesantasa.properties]

Ich kann keinen vollständigen Pfad in env-entry-value definieren. Warum?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage