View Full Version : ldaptemplate without spring
Oct 13th, 2006, 12:48 AM
Is it possible to use LdapTemplate without a spring context? I don't understand how LdapTemplate's contextSource is set up outside of a spring context.
Should I use 1.0.2 or can I use 1.1?
Oct 13th, 2006, 01:22 AM
I think I'm beginning to see how I could possibly do it outside of a spring context. I think I would do something like
LdapTemplate ldapTemplate = new LdapTemplate(contextSource); where contextSource is a class I write that extends LdapContextSource in which I implement getDirContextInstance() and inside that I can put some previous code I wrote "in the old days" to set up a DirContext.
Assuming that will work, my next question is (which I could determine by testing it but I'll try this tomorrow) do I need to include in my classpath all of the libraries in the lib directory; e.g.,
Oct 13th, 2006, 02:11 AM
You don't need to make your own implementation of LdapContextSource; just make sure to call afterPropertiesSet() once the instance properties have been initialized and you should be ok.
I think (but I'm not sure) that you won't need spring-beans.jar and spring-context.jar if you use LdapTemplate outside of a Spring context.
Oct 13th, 2006, 12:31 PM
Sorry, I'm not sure if I explained it correctly because I don't understand your answer. I'm writing a module / class for someone else's app and part of what my module will be doing is some ldap lookups. The other app isn't using spring.
When you say "call afterPropertiesSet() once the instance properties have been initialized" I'm guessing you mean to call that method on the LdapTemplate object? But I don't understand how it will get a ContextSource unless I provide it with one, and I don't understand where to get a ContextSource unless I create one.
Since this is not running in spring there won't be any spring beans, which is where I'd ordinarly define my ContextSource.
Oct 13th, 2006, 01:09 PM
You'll need to manually create your LdapContextSource instance, set the desired properties on that instance and then call afterPropertiesSet() on the LdapContextSource instance. Then you create your LdapTemplate instance, supply the LdapContextSource to that, and you're all set to do your LDAP operations.
Oct 13th, 2006, 01:25 PM
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.