我在JNDI中有一个绑定在“ejb.Bb_restriction_USRemoteHome”下的SessionBean。这也得到了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”检索对象吗?
答案 0 :(得分:1)
您正尝试在全局JNDI上下文中访问JNDI名称“ejb.Bb_restriction_USRemoteHome”。显然,容器可以解析ejb部分,但不能解析“Bb_restriction_USRemoteHome”,因此该名称显然不正确。
您可以尝试简单地列出ejb上下文的内容并从那里开始工作。
对于这个使用类似的东西:
NamingEnumeration namingEnumeration = ctx.list("ejb");
while (namingEnumeration.hasMoreElements()) {
NameClassPair entry = (NameClassPair) namingEnumeration.nextElement();
System.out.println(entry.getName());
}