com.sun.jndi.ldap.LdapCtxFactory:在servlet中找不到类

早上好/下午好,

我有LDAP连接器的问题,当我在我的unit testing中使用它没有问题,但是当它在应用服务器环境中调用时,它似乎有类路径问题,但这个类是用java 1.6.17(版本I)提供的使用)。

我使用spring-ldap来启动我的连接。

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; } 

这是日志:

 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.(AbstractContextSource.java:67) at org.zenithar.security.connectors.impl.ldap.LdapContextFactory.getLdapContextSource(LdapContextFactory.java:16) 

谢谢大家。 问候。

我找到了解决方案^^

Jonas 5是一个在OSGI平台上运行的应用服务器的问题。 我的应用程序是一个共同的核心jar(包含DAO的spring上下文),由3个战争共享。 似乎用于托管共同核心的JVM与用于3次战争的JVM不同。

我添加到我的felix-config.properties

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

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

这样我就可以在我的Common Core中加载com.sun.jndi.ldap.LdapCtxFactory。

谢谢你的帮助。

如果是这种情况,您的unit testing和应用服务器不得使用相同的JRE。 检查您的应用服务器正在使用的内容。

com.sun.jndi.ldap.LdapCtxFactory位于rt.jar中。 你能validation一下吗?

你怎么知道服务器使用的是同一个JVM? 它在本地运行吗? 你有什么JAVA_HOME设置? 哪个app服务器?

不要以为类加载器突然停止工作。 如果您获得的信息与您对世界运作方式的假设相矛盾,请检查您的假设。

您的应用服务器配置错误的可能性远远超过类加载器忘记如何在成功测试和不成功部署之间完成工作。