![](/img/trans.png)
[英]Spring-security-ldap: Failed instantiate InitialContextFactory com.sun.jndi.ldap.LdapCtxFactory
[英]com.sun.jndi.ldap.LdapCtxFactory : class not found in servlet
早上好/下午好
我的LDAP连接器有问题,当我在单元测试中使用它时没问题,但是在应用程序服务器环境中调用它时,似乎有类路径问题,但是此类是在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.<clinit>(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。
谢谢你的帮助。
在这种情况下,您的单元测试和应用服务器不得使用相同的JRE。 检查您的应用服务器正在使用什么。
com.sun.jndi.ldap.LdapCtxFactory
位于rt.jar中。 你能验证一下吗?
您怎么知道服务器正在使用相同的JVM? 它在本地运行吗? 您将JAVA_HOME设置为什么? 哪个应用服务器?
不要以为类加载器突然停止工作。 当您获得的信息与您对世界运作方式的假设相矛盾时,请检查您的假设。
与类加载器忘记如何在成功测试和未成功部署之间完成工作相比,应用服务器配置不正确的可能性更大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.