1
votes

I am using Weblogic 10.3.5 and EJB 3 for session bean

but I am not able to lookup jndi for local stateless session bean even though I am able to lookup

remote bean successfully

my code are for main class is

    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
            "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, "t3://localhost:7001");

    try {

        Context ctx = new InitialContext(p);

        TheBeanRemote bean = (TheBeanRemote) ctx
                .lookup("MrBean#com.bdc.TheBeanRemote");
        System.out.println(bean.sayHello());

        TheLocalLocal bean2 = (TheLocalLocal) ctx.lookup("TheLocalLocal");
        Object obj = ctx.lookup("java:comp/env/ejb/MrBean2");

        System.out.println(bean2.sayHello());

    } catch (Exception e) {
        e.printStackTrace();
    }

Remote Bean

import javax.ejb.Remote;

@Remote public interface TheBeanRemote {

public String sayHello();

}

Local Bean

import javax.ejb.Local;

@Local(TheLocalLocal.class) public interface TheLocalLocal {

public String sayHello();

}

1

1 Answers

0
votes

If you're running as a "client", that is a remote call, if that app is running on the server itself, that is a local call. It makes sense that one works but not the other.

The properties you're using indicate a remote call:

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
        "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(p);

A local call is:

Context context = new InitialContext();

See a similar question here: How to lookup JNDI resources on WebLogic?