Announcement Announcement Module
No announcement yet.
ldaptemplate without spring Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ldaptemplate without spring

    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?
    Last edited by lumpynose; Oct 13th, 2006, 12:53 AM.

  • #2
    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.,
    • commons-collections.jar
    • commons-lang.jar
    • commons-logging.jar
    • spring-beans.jar
    • spring-context.jar
    • spring-core.jar
    • spring-dao.jar
    Last edited by lumpynose; Oct 13th, 2006, 01:26 AM.


    • #3
      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.


      • #4
        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.


        • #5
          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.


          • #6
            Great, thanks!