Results 1 to 6 of 6

Thread: ldaptemplate without spring

  1. #1
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default 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 at 12:53 AM.

  2. #2
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    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
    Code:
    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 at 01:26 AM.

  3. #3
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    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.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  4. #4
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    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. #5
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    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.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  6. #6
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Great, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •