从.properties文件读取参数到.xml文件

前端之家收集整理的这篇文章主要介绍了从.properties文件读取参数到.xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个application.xml文件(directory = WEB-INF / application.xml)

我有一个jasperserver.properties文件(directory = WEB-INF / internal / jasperserver.properties)

这是在jasperserver.properties文件

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

我想从application.xml文件中读取“SERVICE_URL”属性

我该怎么做呢 ?

解决方法

在application.xml中使用PropertyPlaceholderConfigurer.

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

加载属性文件.
然后在application.xml中使用${SERVICE_URL}来替换值:

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

猜你在找的XML相关文章