dinox0r
dinox0r

Reputation: 16039

Is there a way to pass the file location by jndi in a <util:properties /> tag?

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

Upvotes: 1

Views: 1335

Answers (2)

nullPainter
nullPainter

Reputation: 3046

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" />

Upvotes: 4

Rubens Mariuzzo
Rubens Mariuzzo

Reputation: 29241

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

Upvotes: 1

Related Questions