EJB local and remote in the same project

时间:2015-11-12 11:43:17

标签: java ejb

I have an application with DAO, Service, Web.

I want to use EJB local and remote to access my service.

I created an interface to define the methods and an interface with @Local and another with @Remote, according below.

Interface with methods:

public interface OrigemArquivoClient extends BasicCrudFacade<OrigemArquivo, OrigemArquivoSearch, Integer>   {

     public void doSomething();
}

Interface @Local

@Local 
public interface OrigemArquivoClientLocal extends BasicCrudFacade<OrigemArquivo, OrigemArquivoSearch, Integer>, OrigemArquivoClient {

}

Interface @Remote

@Remote
public interface OrigemArquivoClientRemote extends BasicCrudFacade<OrigemArquivo, OrigemArquivoSearch, Integer>, OrigemArquivoClient {
}

To inject the local EJB I am using like bellow and is working.

@EJB(beanName="OrigemArquivoServiceBean")
private OrigemArquivoClientLocal service;

And to remote I am trying to lookup:

bean = ctx.lookup("java:global/" + ear + "/" + projeto + "/" + ejb);

Host that is using to lookup is java:global.EDIEAR.EDIWeb-0.0.1-SNAPSHOT.OrigemArquivoServiceBean. However, in the weblogic exists "!br" at the end of jndi, and when I try to lookup with it ,java:global.EDIEAR.EDIWeb-0.0.1-SNAPSHOT.OrigemArquivoServiceBean!br I have the result bellow, that inst my remote EJB, but a weblogic instance of anything.

Click to image

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

try {
    Context ctx = new InitialContext();
    MyEJBLocal myEjb = (MyEJBLocal) ctx.lookup("java:comp/env/jndiName"); // suppose br???
} catch (NamingException e) {
    throw new EJBException(e);
}