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

痞子三分冷 提交于 2019-12-23 05:45:09

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3447190/com-sun-jndi-ldap-ldapctxfactory-class-not-found-in-servlet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!