从客户端JAVA调用远程EJB

时间:2016-06-10 13:50:25

标签: ejb remote-access wildfly-9

我必须实现两个简单的java项目;第一个是EJB项目,它包含一个实现远程接口的简单服务,第二个项目是一个试图调用这个ejb项目的java客户端, 所以这就是我到现在所做的:

Context context = new InitialContext(jndiProperties);
    TestServiceRemote proxy = (TestServiceRemote) context
            .lookup("java:global/testEJB/TestService!services.TestServiceRemote");
    System.out.println(proxy.showHello());

这是我的ejb服务:

@Stateless
public class TestService implements TestServiceRemote {

public TestService() {

}

@Override
public String showHello() {
    return "Hello";

}

}

最后我的远程界面:

@Remote
public interface TestServiceRemote {
   public String showHello();
}

我已经在WIldfly 9中部署了EJB,但是当我启动java客户端时,我在控制台中显示了这个错误:

Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at swing.testClient.main(testClient.java:22)

有人能告诉我我的代码中有什么问题吗?

1 个答案:

答案 0 :(得分:0)

默认情况下,def record(list_to_extend, extend_length): list_to_extend.extend(1 for _ in range(extend_length) 命名空间在Java中不可用。您可以将主类作为应用程序客户机JAR打包在EAR中,并使用应用程序客户机容器启动程序运行它,或者您可以配置InitialContext以访问java:命名空间,如this blog post中所述

相关问题