I would like to have palceholder in my xml file which places the value from a properties file.
The SystemProperty.xml file is just a global system configuration file, not any kind of spring configuration, which looks like that
<?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
<Property>
<Name>CommandTimeout</Name>
<Value>60</Value>
<Description>Setting the timeout(in seconds)</Description>
<DefaultValue></DefaultValue>
</Property>
<Property>
<Name>Address</Name>
<Value>${server.IP}</Value>
<Description>ip:port</Description>
<DefaultValue></DefaultValue>
</Property>
</PropertyList>
It is using by XMLConfiguration bean to loading in
<bean
id="xmlConfiguration"
class="org.apache.commons.configuration.XMLConfiguration"
lazy-init="true">
<constructor-arg type="java.lang.String">
<value>SystemProperty.xml</value>
</constructor-arg>
<property name="expressionEngine">
<bean class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine" />
</property>
</bean>
And use it in my code as below
@Autowired
@Qualifier("xmlConfiguration")
XMLConfiguration xmlConfiguration;
However, the ${server.IP} placeholder doesn't work any.
In the other hand, for spring configuration xml, I can do that. For example, I have a Scheduler.xml which is Quartz configuration xml as below.
<property name="quartzProperties">
<props>
<prop key="org.quartz.jobStore.dataSource">PostgreSQLQuartzDataSource</prop>
<prop key="org.quartz.dataSource.PostgreSQLQuartzDataSource.driver">org.postgresql.Driver</prop>
<prop key="org.quartz.dataSource.PostgreSQLQuartzDataSource.URL">jdbc:postgresql://${scheduler.db.host}:${scheduler.db.port}/${scheduler.db.database}</prop>
<prop key="org.quartz.dataSource.PostgreSQLQuartzDataSource.user">${scheduler.db.username}</prop>
<prop key="org.quartz.dataSource.PostgreSQLQuartzDataSource.password">${scheduler.db.password}</prop>
<prop key="org.quartz.dataSource.PostgreSQLQuartzDataSource.maxConnections">10</prop>
...
</props>
</property>
And application.properties file as below
# Quartz scheduler database resource
scheduler.db.host=127.0.0.1
scheduler.db.port=5432
scheduler.db.database=scheduler
scheduler.db.username=test
scheduler.db.password=test
# Server settings
server.IP=192.168.111.12
By using PropertyPlaceholderConfigurer bean:
<bean
id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:application.properties</value>
</list>
</property>
</bean>
And of cause import the Scheduler.xml in SpringApplication-context.xml
<import resource="Scheduler.xml" />
Is it possible to import properties into a normal XML file for using placeholder? Can I set up it in XMLConfiguration or any other ways?
Any help is appreciated.