reading parameter from .properties file to .xml file

Andre picture Andre · Aug 5, 2013 · Viewed 16.9k times · Source

I have a application.xml file (directory = WEB-INF/application.xml)

and I have a jasperserver.properties file (directory = WEB-INF/internal/jasperserver.properties)

This is in the jasperserver.properties file

SERVICE_URL=http://b-reptest-lnx.nwu.ac.za:8026/jasperserver-pro/j_spring_cas_security

I want to read that "SERVICE_URL" property from the application.xml file

How do I do this ?

Answer

Luca Basso Ricci picture Luca Basso Ricci · Aug 5, 2013

use PropertyPlaceholderConfigurer in application.xml.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
    <value>classpath:path/to/jasperserver.properties</value>
  </property>
</bean>

to load properties file. Then use ${SERVICE_URL} in your application.xml to substitute values:

<bean class="your class">
  <property name="serviceURL"><value>${SERVICE_URL}</value></property>
</bean>