Java LDAP/JNDI连接问题:需要在环境或系统属性中指定类名,或作为小程序参数,或在应用程序资源中指定类名

Java LDAP/JNDI连接问题:需要在环境或系统属性中指定类名,或作为小程序参数,或在应用程序资源中指定类名,java,ldap,jndi,Java,Ldap,Jndi,在我的java项目中,我需要访问LDAP,我正在使用下面的代码进行访问 public static LdapContext openConnection() throws AxisFault,Exception { if (ctxGC == null) { ctxGC = getCtxGC(); } return ctxGC; } private static LdapContext getCtxG

在我的java项目中,我需要访问LDAP,我正在使用下面的代码进行访问

    public static LdapContext openConnection() throws AxisFault,Exception {
        if (ctxGC == null) {
            ctxGC = getCtxGC();
        }
        return ctxGC;
    }

    private static LdapContext getCtxGC() {
        // TODO Auto-generated method stub
        LdapContext context = null;
        Map<String, String> map = LDAPUtility.getLDAPParameters();
        String user = map.get("userName");
        String pass = map.get("password");
        String ldapHost = map.get("hostName");
        String domain = map.get("domain");

        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, ldapHost);
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, user + "@" + domain);
        env.put(Context.SECURITY_CREDENTIALS, pass);

        try {
            context = new InitialLdapContext(env, null);
            log.debug("LDAP context initialized successfully !");
            return context;
        } catch (NamingException nex) {
            log.error("Exception occured", nex);
        }
        return context;
    }

有人对此有想法吗?

可能是LDAPUtility.getLDAPParameters()失败了;?不,没关系,我已经记录下来检查过了@jwilleke。
    javax.naming.NoInitialContextException","exception_message":"Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial","stacktrace":"javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial