Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建远程连接失败,原因是:java.lang.RuntimeException:操作失败,状态为等待_Java_Jboss_Jndi_Ejb 3.1 - Fatal编程技术网

创建远程连接失败,原因是:java.lang.RuntimeException:操作失败,状态为等待

创建远程连接失败,原因是:java.lang.RuntimeException:操作失败,状态为等待,java,jboss,jndi,ejb-3.1,Java,Jboss,Jndi,Ejb 3.1,无法创建远程连接。请看控制台。 javax.naming.NamingException:未能创建远程连接[根异常为java.lang.RuntimeException:操作失败,状态为等待] package com.as.service; import javax.ejb.Remote; @Remote public interface CalculetteService { int add(int a, int b); } package com.fpt.service; im

无法创建远程连接。请看控制台。 javax.naming.NamingException:未能创建远程连接[根异常为java.lang.RuntimeException:操作失败,状态为等待]

package com.as.service;

import javax.ejb.Remote;

@Remote
public interface CalculetteService {
   int add(int a, int b);
}


package com.fpt.service;
import javax.ejb.Stateless;
import org.jboss.logging.Logger;


@Stateless
public class CalculetteServiceImpl implements CalculetteService{

  private Logger log = Logger.getLogger(CalculetteServiceImpl.class);

  @Override
  public int add(int a, int b) {
    return a + b;
  }
}


package com.as.test;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.as.service.CalculetteService;
import com.as.service.CalculetteServiceImpl;

public class Test {


public static void main(String[] args) {

    CalculetteService calculette = null;

    try {

        Properties properties = new Properties();
        properties.setProperty("java.naming.factory.url.pkgs",    "org.jboss.ejb.client.naming");
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        properties.setProperty("java.naming.provider.url","remote://localhost:4447");
        properties.setProperty("jboss.naming.client.ejb.context", "true");
        properties.setProperty("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");


        Context context = new InitialContext(properties);


        calculette =  (CalculetteService)context.lookup("calculetteService#com.fpt.service.CalculetteService");
        System.out.println("La somme est:"+calculette.add(10, 10));
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

将服务器从JBoss AS 7.1.1更改为Wildfly 8.X。选择一种方法来调用EJB。我使用了远程命名项目()。谢谢,这对我很有用。