1

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!

Batiaev
  • 1,173
  • 1
  • 14
  • 30
Vicky
  • 16,679
  • 54
  • 139
  • 232
  • Possible duplicate: http://stackoverflow.com/a/8999771/227140 – beny23 May 10 '16 at 04:44
  • Possible duplicate of [Spring Jndi Context and PropertyPlaceholderConfigurer](http://stackoverflow.com/questions/8998704/spring-jndi-context-and-propertyplaceholderconfigurer) – beny23 May 10 '16 at 04:45
  • @beny23: Its not a duplicate question. As I want to combine both properties in a single array in my XML and then access it from my class. I don't want any property name hardcoded in my class in any manner for accessing the value. – Vicky May 10 '16 at 04:47
  • Don't use a `PropertyPlaceholderConfigurer` for that. Use `` for that. Also I strongly suggest to use `` instead of `PropertyPlaceholderConfigurer`. What is there reason you need the full properties instead of using placeholders? – M. Deinum May 10 '16 at 08:18

0 Answers0