Przeczytaj zmienną środowiskową z applicationContext.xml
Potrzebuję przeczytać zmienną środowiskową zdefiniowaną w moim pliku 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>C:/V3</env-entry-value>
</env-entry>
od mojegoapplicationContext.xml
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${PATH_ENV}/myprop.properties" />
</bean>
Jak mogę to zrobić ?
Wreszcie zrobiłem następny:
1 Zdefiniuj zmienną środowiskową w context.xml:
<Environment name="PATH_ENV" type="java.lang.String"/>
2 Zdefiniuj env-entry w 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 Zdefiniuj w 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>
To działa poprawnie, ale jeśli zdefiniuję pełną ścieżkę w:
<env-entry-value>C:/V3/</env-entry-value>
Mam następny problem:
java.io.FileNotFoundException: Could not open ServletContext resource [/C:/V3/aesantasa.properties]
Nie mogę zdefiniować pełnej ścieżki w wartości env-entry Dlaczego?