Announcement Announcement Module
No announcement yet.
ldapTemplate is null in bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ldapTemplate is null in bean

    The ldapTemplate is null in the bean that is getting it. No errors, what can I do to troubleshoot?


  • #2
    We'll need more information in order to track down this problem, i.e. code, configuration files and stack trace.


    • #3
      More information...

      Here is the bean configuration and the code. I am using other beans in my configuration that are working so I know spring is reading the file.

      <bean id="contextSource"
      class=" e">
      <property name="url" value="ldap://" />
      <property name="base" value="dc=AAC,dc=USAREC,dc=ARMY,dc=MIL" />
      <property name="userName" value="cn=DSAMEUSER,ou=DSAME Users;dc=aac,dc=usarec,dc=army,dc=mil" />
      <property name="password" value="n0password" />

      <bean id="ldapTemplate"
      <constructor-arg ref="contextSource" />
      <bean id="ldapDao"
      class=" pDao">
      <property name="ldapTemplate" ref="ldapTemplate" />


      import java.util.Iterator;
      import java.util.List;

      import javax.naming.NamingException;

      import org.apache.log4j.Logger;

      import net.sf.ldaptemplate.AttributesMapper;
      import net.sf.ldaptemplate.LdapTemplate;

      public class LdapDao {
      private LdapTemplate ldapTemplate;
      private static final Logger log = Logger.getLogger(LdapDao.class);

      public void setLdapTemplate(LdapTemplate ldapTemplate) {
      this.ldapTemplate = ldapTemplate;

      public String getRoleCodeForRctrId(String RctrId) {
      List roleCodes = getAllRolesForId(RctrId);
      Iterator it = roleCodes.iterator();
      String roleCd = "";
      while (it.hasNext()){
      roleCd = (String);
      return roleCd;

      private List getAllRolesForId(String RctrId) {
      log.debug("RctrId value " + RctrId);
      log.debug("Template object " + ldapTemplate);
      return"", "(RctrId=" + RctrId + ")",
      new AttributesMapper() {
      public Object mapFromAttributes(Attributes attrs)
      throws NamingException {
      return attrs.get("LEADSRoles").get();



      • #4
        Log messages

        Here is what I am getting in the log:

        2006-08-01 08:38:31,881 DEBUG [main] support.AbstractContextSource - AuthenticationSource not set - using default implementation
        2006-08-01 08:38:31,972 DEBUG [main] support.AbstractContextSource - Using LDAP pooling.
        2006-08-01 08:38:31,974 DEBUG [main] support.AbstractContextSource - Trying provider Urls: ldap://,dc=USAREC,dc=ARMY,dc=MIL


        • #5
          Well, on a quick glance I can't see anything wrong with the configuration files or the code (I'm assuming the spaces in the configuration file are typos in the forum post).

          I suggest debugging to see whether setLdapTemplate() gets called, and if so, that the LdapDao instance being used is the one configured in the Application Context.


          • #6
            Problem solved

            Thanks for the advise. I checked the setLdapTemplate method and the value is being set properly. I was NOT injecting the LdapDao into the bean that uses it, so it was creating a new reference that did not have the ldapTemplate object set.