I want to read properties from two places:
a) A JNDI entry with jndi-name
environment/config
configured on WebSphere server as a resource environment entry.
my.color.property=abc
my.size.property=pqr
b) A properties file config.properties
on my class path.
propa=xyz
propb=def
propc=mno
I want some way to read all the above 5 properies (2 from JNDI and 3 from property file) as PropertiesArray
.
I found the following way to do it for the JNDI:
<jee:jndi-lookup id="myJndiProperties" jndi-name="environment/config" expected-type="java.util.Properties"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="propertiesArray">
<list>
<ref bean="myJndiProperties" />
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
Now autowiring myJndiProperties
in my class and then using it as below gives the property entries from JNDI:
@Autowired
private Properties myJndiProperties;
and then
for (final String name: myJndiProperties.stringPropertyNames()) {
System.out.println(myJndiProperties.getProperty(name));
}
How do I do the same for the properties file ? How do I combine both property entries in JNDI and property file as one PropertiesArray
.
The following is not working:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="propertiesArray">
<list>
<ref bean="myJndiProperties" />
<value>classpath:config.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
I am using Spring 3.2.5 with Java 7.
Thanks for reading!