Не удалось разрешить ‹JNDI›

У меня есть SessionBean в JNDI, связанный с "ejb.Bb_restriction_USRemoteHome". Это также подтверждается консолью Weblogic.

Но при доступе к нему через следующий фрагмент кода:

private static Context getInitialContext() throws NamingException {
      Context ctx = null;
      Hashtable ht = new Hashtable();
      ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
      ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
      ctx = new InitialContext(ht);
      return ctx;
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    try {
        Context ctx = getInitialContext();
        System.out.println(ctx.list("java:comp/env"));
        System.out.println(ctx.lookup("ejb.Bb_restriction_USRemoteHome").getClass());
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

, я получал следующую ошибку:

javax.naming.NameNotFoundException: Unable to resolve 'ejb.Bb_restriction_USRemoteHome'. Resolved 'ejb'; remaining name 'Bb_restriction_USRemoteHome'
    at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
    at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
    at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
    at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
    at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at TestServlet.doGet(TestServlet.java:50)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)

Вывод "System.out.println(ctx.list("java:comp/env"));" только для weblogic.jndi.internal.NameClassPairEnumeration@aee30f.

Кто-нибудь может сказать мне, как получить объект с именем JNDI "ejb.Bb_restriction_USRemoteHome"?


person Rishi    schedule 12.06.2011    source источник
comment
Вы можете показать свою запись ejb-jar.xml для сеансового компонента?   -  person JoseK    schedule 13.06.2011


Ответы (1)


Вы пытаетесь получить доступ к имени JNDI "ejb.Bb_restriction_USRemoteHome" в глобальном контексте JNDI. По-видимому, контейнер может разрешить часть ejb, но не «Bb_restriction_USRemoteHome», так что это имя явно неверно.

Вы можете попробовать просто перечислить содержимое контекста ejb и работать оттуда.

Для этого используется что-то вроде:

NamingEnumeration namingEnumeration = ctx.list("ejb");
while (namingEnumeration.hasMoreElements()) {
    NameClassPair entry = (NameClassPair) namingEnumeration.nextElement();
    System.out.println(entry.getName());
}
person Arjan Tijms    schedule 12.06.2011