I have properties file config.properties where are stored some application wide properties. And I have imported it using property placeholder:
PropertyPlaceholderConfigurer already supports xml property files via the DefaultPropertiesPersister
The xml file format for the properties is as below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="key1">Value 1</entry>
<entry key="key2">Value 2</entry>
</properties>
you can use
<context:property-placeholder
location="classpath:/com/myProject/spring_prop.xml" />
<bean id="bean" class="org.MyBean">
<property name="key1" value="${key1}" />
</bean>
In addition to the other answer here, I have also seen xml properties loaded directly as named properties files:
The spring file contains:
<util:properties id="myXmlProps" location="classpath:/com/myProject/spring_prop.xml" />
This can then be accessed via springs expression language as:
"#{myXmlProps['key1']}"
And injected into Strings in classes with:
@Value("#{myXmlProps['key1']}")
private String aValueForKey1;