本文介绍了JNDI“无法实例化类:org.jboss.naming.remote.client.InitialContextFactory"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 JBoss 服务器用于 EJB 我需要在控制台应用程序中使用 JNDI 来获取会话 bean 的引用,控制台应用代码看起来像这样
I'm using JBoss Server for EJB And I need JNDI in console app to get reference of session bean,console app code looks like this
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Program {
public static void main(String[] args) throws NamingException {
// TODO Auto-generated method stub
Properties pr = new Properties();
pr.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
pr.put(InitialContext.PROVIDER_URL,"remote://localhost:4447");
InitialContext ic = new InitialContext(pr);
}
}
当我运行应用程序时出现异常
when I run the application I get exception
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at Program.main(Program.java:14)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 5 more
推荐答案
您可以使用以下上下文进行连接.我已经尝试并测试来设置它.
You can use following context to connect.I have tried and tested to set up this.
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
public class Program {
public static void main(String[] args) throws NamingException {
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser");
jndiProps.put(Context.SECURITY_CREDENTIALS, "testpassword");
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);
}
}
然后我得到这个错误
JBREM000200: Remote connection failed: javax.security.sasl.SaslException:
Authentication failed: all available authentication mechanisms failed - Could
not register a EJB receiver for connection to remote://localhost:4447
java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication
failed: all available authentication mechanisms failed.
然后我使用 add-user.sh 添加了用户.
Then i added the user using add-user.sh.
握手成功消息来了.
这篇关于JNDI“无法实例化类:org.jboss.naming.remote.client.InitialContextFactory"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!