创建EJBClient时无法连接到服务器

时间:2017-05-15 08:41:15

标签: java ejb

我有一个EJB客户端如下:

public class EJBTestClient {

  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,"http-remoting://localhost:8080");  // create a context passing these properties  Context ctx = new InitialContext(jndiProps);
    jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
    InitialContext context = new InitialContext(jndiProps);
    System.out.println("Context lookup finished");

    MyFirstEJBRemote proxy = (MyFirstEJBRemote) context.lookup("MyFirstEJB/Remote");
    System.out.println(proxy.getClass().toString());

    System.out.println(proxy.getDescription());

    proxy.doSomething();

  }
}

但是当我运行该程序时,它显示了异常javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [http-remoting://127.0.0.1:8080 (java.io.IOException: JBREM000202: Abrupt close on Remoting connection 0c05035f to /127.0.0.1:8080 of endpoint "config-based-naming-client-endpoint" <2ce1483d>)]

我的EJB容器名为EJBTestApp,其中包含 MyFirstEJB无状态会话Bean MyFirstEJBRemote接口

@Stateless
@Remote
public class MyFirstEJB implements MyFirstEJBRemote {

private Logger log = Logger.getLogger(MyFirstEJB.class);
/**
 * Default constructor. 
 */
public MyFirstEJB() {
    // TODO Auto-generated constructor stub
}

@Override
public void doSomething() {
    log.info("doSomething() has been call"); 

}

@Override
public String getDescription() {
    return "getDescription() has returned some values";
}

}

此EJB容器部署在localhost:8080下的Wildfly 10上。任何人都可以帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

尝试设置

jndiProps.put(jboss.naming.client.ejb.context, true);

将来自wildfly10directory / bin / client的库添加到项目

如果不起作用,请尝试将查找设置为:

MyFirstEJBRemote proxy = (MyFirstEJBRemote) context.lookup("MyFirstEJB/BeanName!path_to_package_remote_bean");