com.sun.jndi.ldap.LdapCtxFactory : class not found

2019-06-14 13:29发布

Good morning / afternoon,

I have a problem with LDAP connector, when I use it in my unit test no problem, but when it was called in a application server environment, it seems to have classpath issue, but this class is delivred with java 1.6.17 (version I use).

I use spring-ldap to initiate my connection.

public static LdapContextSource getLdapContextSource(final String url, final String base) throws Exception {
    LdapContextSource ldapContextSource = new LdapContextSource();

    ldapContextSource.setUrl(url);
    ldapContextSource.setBase(base);
    ldapContextSource.setPooled(true);
    //ldapContextSource.setContextFactory(LdapCtxFactory.class);

    ldapContextSource.afterPropertiesSet();

    return ldapContextSource;
}

Here is the log :

2010-08-10 09:46:38,183 : StandardWrapperValve.invoke : Servlet.service() for servlet default threw exception
java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at org.ow2.easybeans.loader.EasyBeansClassLoader.findClass(EasyBeansClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at org.ow2.easybeans.loader.EasyBeansClassLoader.loadClass(EasyBeansClassLoader.java:238)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.springframework.ldap.core.support.AbstractContextSource.class$(AbstractContextSource.java:67)
    at org.springframework.ldap.core.support.AbstractContextSource.<clinit>(AbstractContextSource.java:67)
    at org.zenithar.security.connectors.impl.ldap.LdapContextFactory.getLdapContextSource(LdapContextFactory.java:16)

Thanks for all. Regards.

2条回答
仙女界的扛把子
2楼-- · 2019-06-14 14:02

Your unit test and app server must not be using the same JRE if that's the case. Check to see what your app server is using.

com.sun.jndi.ldap.LdapCtxFactory is in rt.jar. Can you validate that?

How do you know that the server is using the same JVM? Is it running locally? What do you have JAVA_HOME set to? Which app server?

Don't assume that the class loader suddenly stopped working. When you get information that contradicts your assumptions about how the world works, check your assumptions.

It's far more likely that your app server isn't configured properly than the class loader forgot how to do its job between your successful test and your unsuccessful deployment.

查看更多
叼着烟拽天下
3楼-- · 2019-06-14 14:18

I found the solution ^^

It was a problem with Jonas 5 wich is an app server running on OSGI platform. My application is a common core jar (containing spring context with DAO) shared by 3 wars. It seems that the JVM used to host the common core is not the same as used for the 3 wars.

I add to my felix-config.properties

org.osgi.framework.bootdelegation=....
    sun.util.calendar; \
    com.sun.jndi.ldap; \
    version="1.5.0"

And

org.osgi.framework.bootdelegation=com.sun.corba, \
....
com.sun.jndi.ldap.*

So that I can load com.sun.jndi.ldap.LdapCtxFactory in my Common Core.

Thanks for your help.

查看更多
登录 后发表回答