Tôi cần đọc một biến môi trường quy định tại web.xml của tôiĐọc một biến môi trường từ applicationContext.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>
từ tôi applicationContext.xml
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${PATH_ENV}/myprop.properties" />
</bean>
Làm thế nào tôi có thể làm điều này?
Cuối cùng tôi đã làm tiếp theo:
1 Xác định biến môi trường trong context.xml:
<Environment name="PATH_ENV" type="java.lang.String"/>
2 Xác định env-entry trong 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 Xác định trong 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>
này được điều hành một cách chính xác, nhưng nếu tôi xác định một đường dẫn đầy đủ trong:
<env-entry-value>C:/V3/</env-entry-value>
Tôi có vấn đề tiếp theo:
java.io.FileNotFoundException: Could not open ServletContext resource [/C:/V3/aesantasa.properties]
tôi không thể xác định một đường dẫn đầy đủ trong env-entry- Tại sao?
Trong trường hợp bất kỳ ai đến theo câu hỏi này, nó phải là tập tin ': C:/V3/ env-entry-value>' –
Jamie