PDA

View Full Version : Configuring Environment specific LDAP context



santoshB
Mar 7th, 2007, 04:19 AM
I am using spring-LDAP 1.1.1. The context configuration is as below.

<bean id="contextSource" class="org.springframework.ldap.support.LdapContextSource">
<property name="url" value="ldap://<hostname>:389" />
<property name="base" value="<base>" />
<property name="userName" value="<user ID>" />
<property name="password" value="<password>" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>

In my code, I use the ldapTemplate to interact with LDAP.

When the code is moved to a different environment, the properties change. One way I thought to handle it is - to define the beans something like contextSource_DEV, contextSource_STAGING, contextSource_PROD and use them accordingly depending on the environment specific system property.

Is there any other better way of doing it - doing it just with the configuration, without having to change the code. Let me know if there is any documentation for the same.

Thanks
santosh

rasky
Mar 7th, 2007, 04:36 AM
This should be managed using configuration properties. In short you can refer from your bean definition file to an external .properties file and use these properties in your context file using the '{}' notation. You will then use different .properties files in the different environments.

The above is documented in the Spring Framework main reference documentation. Look for PropertyPlaceholderConfigurer.

santoshB
Mar 7th, 2007, 07:43 AM
It works. Thanks.