This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.
It you need the DirContext object I guess you need it for performing LDAP operations on, right? You get a DirContext instance by calling ContextSource.getReadOnlyContext/getReadWriteContext. However, you'd be better of calling LdapTemplate.executeReadOnly/executeReadWrite. That way you just don't need to worry about context creation and closing.
If you want you can create your own ContextSource implementation that just retrieves the instance from jndi.
But really, it doesn't seem to be such a good idea to have a DirContext instance stored in jndi and using that instance everywhere you do LDAP. That would be like placing a single DB connection in jndi and using it everywhere you do SQL.
Thanks for your informative answers, I think I can build something out of them.
I have a kind of "legacy" application, so I wouldn't want to change the code.
The code gets injected with a DirContext object, with which it runs ldap-operations, eg. ctx.lookup(dn).
I don't need to worry about closing/opening connections, that just works when using jboss's namingcontext.
Just FYI, here how it's configured (in jboss, ie. a DirContext is ultimately stored in JNDI and from there it can be had with spring and injected).
I am having the same problem right now. So searched out this very old discussion.
I am using jboss 5.1. My jndi returns the DirContext. So far that works fine.
However I agree with you that it's better to store the ContextSource in jndi.
But how to configure the jndi so that it can create and return ContextSource?
Another could be jboss question. How to make it as a pool in JBoss?
Last edited by PeterSaw; Jun 19th, 2012, 08:52 PM.