Andre
Andre

Reputation: 661

reading parameter from .properties file to .xml file

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 ?

Upvotes: 4

Views: 20529

Answers (2)

Suryaprakash Pisay
Suryaprakash Pisay

Reputation: 648

I think your jasperserver.properties is not in your classpath.

remove classpath given in value tag in bean definition , below is the modified

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
    <value>/WEB-INF/internal/jasperserver.properties</value>
  </property>
</bean>

Then try it

Other wise copy jasperserver.properties to src folder and add modified bean below mentioned

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

Hope it will help.

Upvotes: 1

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18403

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>

Upvotes: 6

Related Questions