1

I have the following properties declared in my spring-config.xml

<util:properties id="ldap" location="classpath:com/company/project/resources/some_configuration.properties"/>

Then I inject the values contained in the properties into some member variables using the spring @Value annotation in a service implementation (this approach is by far the cleanest/most elegant I have used in the implementation of the service and if possible I wouldn't want to change it).

The problem with this layout is that I have to modify the properties file and regenerate the application war for every deployment environment (quality, production, etc) and the server admins want to configure the some_configuration.properties path by JNDI (the application server is JBoss)

How can I pass the file location by jndi in the <util:properties /> tag?

Any help and suggestions would be appreciated

edit: It would be nice if somebody comes out with a solution where I could do something like:

<util:properties id="ldap" location="jndi:url/some_configuration.properties"/>

Or similar

higuaro
  • 15,730
  • 4
  • 36
  • 43

2 Answers2

4

Old post, but this may be useful for others:

<jee:jndi-lookup id="ldapProps" jndi-name="your/jndi" resource-ref="true"/>
<util:properties id="ldap" location="file://#{ldapProps}/some_configuration.properties" />
nullPainter
  • 2,676
  • 3
  • 22
  • 42
  • Thanks, this was what I was looking for! We've being resorting to other methods to achieve something similar – higuaro Jul 30 '13 at 01:43
  • 1
    Same - I got sufficiently frustrated today by our workarounds to be motivated enough to get JNDI to work :) – nullPainter Jul 30 '13 at 01:54
1

I was looking something similar, this answer will help you using PropertyPlaceholderConfigurer: https://stackoverflow.com/a/3486315/439427.

HTH


In your case you will need to configure the PropertyPlaceholderConfigurer in your beans then you will just need to do the following change:

<util:properties id="ldap"
  location="classpath:x/y/z/resources/${environment}.properties"/>

Where ${environment} will be set by an environment variable like this: -Denvironment=dev

Community
  • 1
  • 1
Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
  • Thanks, I'm checking it, but I still would like to know if there is a way of doing the same by jndi – higuaro May 23 '12 at 20:44
  • I like the approach, but if the server configuration changes (port, ip, domain, etc), I have to edit the properties files and regenerate the war, something that the admin team don't want to, they want to edit an external file so they don't need the developer assistance for the task (if they could do it by jndi would be a big plus because they already have a jndi capable server) – higuaro May 23 '12 at 20:54