1

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();

}

user432843
  • 83
  • 1
  • 9

1 Answers1

0

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?

Community
  • 1
  • 1
Display Name is missing
  • 6,197
  • 3
  • 34
  • 46
  • Thanks for reply, When I am using context object without passing Properties object and try to access as you have suggested above for local bean then I am getting following javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial Please let me know where is problem because from many day I am facing same problem Thanks!!! – user432843 Nov 04 '14 at 13:42
  • Can you post the full exception? - you can edit your original question to add more info. Sounds like it might be a classpath issue – Display Name is missing Nov 04 '14 at 15:31
  • full exception:: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325) at javax.naming.InitialContext.lookup(InitialContext.java:392) at com.bdc.Main.main(Main.java:33) – user432843 Nov 05 '14 at 16:14