0

我是 EJB 和 JBoss 世界的新手,在尝试通过其远程接口执行无状态 bean 时遇到问题。

我在 Struts ActionSupport 中这样做:

public String inscrire() {
    System.out.println("########### Inscrire Action #############");
    Candidat c = new Candidat(nom, prenom, mail, telephone, ecole);
    try {
        final Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                org.jboss.naming.remote.client.InitialContextFactory.class
                        .getName());
        env.put(Context.PROVIDER_URL, "remote://localhost:4447");
        env.put(Context.SECURITY_PRINCIPAL, "UserApp");
        //env.put("jboss.naming.client.ejb.context", "true");
        env.put(Context.SECURITY_CREDENTIALS, "password");
        InitialContext remoteContext = new InitialContext(env);
        System.out.println("########## Initial Context OK ##########");

        servicecandidat = (CandidatSessionRemote) remoteContext
                .lookup("java:global/EtestEAProject/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionRemote");
        System.out.println("########## LookUp OK ##########");

        if (servicecandidat.inscrireCandidat(c))
            return SUCCESS;
        else
            return ERROR;
    }catch (Exception lookupError) {
        System.out.println("########## LookUp Echec ##########");
        lookupError.printStackTrace();
        return ERROR;
    }

尝试执行方法时,控制台会给出以下命名异常

15:01:45,474 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) ########## Initial Context OK ##########

15:01:45,680 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) ########## LookUp Exchec ##########

15:01:45,682 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.naming.NameNotFoundException: global/EtestEAProject/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionRemote -- service jboss.naming.context.java.jboss.exported.global.EtestEAProject.EtestMetier."CandidatSession!sessions.candidat.CandidatSessionRemote"

15:01:45,685 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

15:01:45,687 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)     at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
...........................

ejb jar 部署说:

java:global/EtestEAProject/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionRemote

    java:app/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionRemote

    java:module/CandidatSession!sessions.candidat.CandidatSessionRemote

    java:jboss/exported/EtestEAProject/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionRemote

    java:global/EtestEAProject/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionLocal

    java:app/EtestMetier/CandidatSession!sessions.candidat.CandidatSessionLocal

    java:module/CandidatSession!sessions.candidat.CandidatSessionLocal
4

1 回答 1

0

好的,因为你的包如下:

EAR
|-- WAR
`-- EJB-JAR

那么进行 EJB 查找的最佳方法是:

ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-remote-interface>

在你的情况下:

ejb:EtestEAProject/EtestMetier//CandidatSession!sessions.candidat.CandidatSessionRemote

是的,'//' 是正确的,因为不同的名称是一个空字符串。

获取进行查找的方法应该类似于:

public CandidatSessionRemote getEJB() {
    Hashtable jndiProperties = new Hashtable();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    Context context = new InitialContext(jndiProperties);
    return (CandidateSessionRemote) context.lookup("ejb:EtestEAProject/EtestMetier//CandidatSession!sessions.candidat.CandidatSessionRemote");
}

希望这会有所帮助,如果您有任何其他问题,请告诉我。

于 2012-12-18T21:40:05.383 回答