所有,
我试图从远程独立程序调用EJB。 EJB已在JBOSS 7.0上正确部署。我使用以下代码进行查找:
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProps.put(Context.SECURITY_PRINCIPAL, "user1");
jndiProps.put(Context.SECURITY_CREDENTIALS, "password@123?");
jndiProps.put("jboss.naming.client.ejb.context", true);
try {
Context ctx = new InitialContext(jndiProps);
HelloWorld d= (HelloWorld) ctx.lookup("HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld");
// String s=d.sayHello();
// System.out.println(s);
}
catch(Exception ne) {
ne.printStackTrace();
}
但我得到以下异常,无法继续进行。任何人都可以让我知道我错过了什么:
Failed to connect to any server. Servers tried: [http-remoting://localhost:8080]
javax.naming.NamingException: Failed to connect to any server. Servers tried: [http-remoting://localhost:8080]
我的服务器已启动并正在运行,我使用的是standalone-full.xml文件
我认为你的JBoss版本(AS 7)中没有http-remoting:
协议。
更改您的提供商URL
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
至
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
此外,请确保在客户端的类路径中包含所有必需的JBoss EJB远程处理项目库。