【问题标题】:javax.naming.NameNotFoundException: While trying to lookup 'abc' didn't find subcontext 'abc'javax.naming.NameNotFoundException:尝试查找“abc”时未找到子上下文“abc”
【发布时间】:2018-10-25 23:25:32
【问题描述】:

我开发了一个带有远程接口的 EJB 应用程序。此应用程序部署在 weblogic 12 上。

使用 java 应用程序,我正在尝试使用我的 EJB 应用程序,但是当我从类 InitialContext 调用方法查找时,我收到此消息“javax.naming.NameNotFoundException:尝试查找'NewSessionBean.remote'时没有' t 找到子上下文“NewSessionBean”

这是来自远程接口的代码:

package co.com.tutorial.stateless;

import java.util.List;
import javax.ejb.Remote;

/**
 *
 * @author jquintep
 */
@Remote
public interface NewSessionBeanRemote {

    void addBook(String bookName);

    List getBooks();
}

这是实现代码的一部分:

package co.com.tutorial.stateless;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author jquintep
 */
@Stateless
public class NewSessionBean implements NewSessionBeanRemote {

    List<String> bookShelf;

    public NewSessionBean() {
        bookShelf = new ArrayList<String>();
    }

这是我调用查找时代码的一部分:

 try {
         int choice = 1; 
         NewSessionBeanRemote  libraryBean = 
         (NewSessionBeanRemote)ctx.lookup("NewSessionBean/remote");

感谢您考虑我的请求。

PS 我在 tutorialspoint 关注 EJB 教程。

【问题讨论】:

    标签: jakarta-ee ejb weblogic


    【解决方案1】:

    您可以通过 Weblogic 控制台中的以下路径查看您的 JNDI 树

    环境 -> 服务器 -> 选择你的服务器 -> 点击查看 JNDI 树链接

    我总是检查 JNDI 树的查找问题。

    为什么不使用 JNDI 可移植名称进行查找?

    https://docs.oracle.com/cd/E19798-01/821-1841/girgn/index.html

    如果您已将实现部署为单独的 EAR,则可以使用以下查找

    ctx.lookup("java:global/[your ear name]/[your jar file name(module name)]/NewSessionBean!co.com.tutorial.stateless.NewSessionBeanRemote");
    

    如果您已将实现部署为单独的 jar,则可以使用以下查找

    ctx.lookup("java:global/[your jar file name(module name)]/NewSessionBean!co.com.tutorial.stateless.NewSessionBeanRemote");
    

    如果您想在同一个 EAR 但在不同的 jar 中查找

    ctx.lookup("java:app/[your jar file name(module name)]/NewSessionBean!co.com.tutorial.stateless.NewSessionBeanRemote");
    

    如果你想在同一个 EAR 和同一个 jar 中查找

    ctx.lookup("java:module//NewSessionBean!co.com.tutorial.stateless.NewSessionBeanRemote");
    

    【讨论】:

    • 谢谢,我检查了我服务器上的 JNDI 树,并按照您的示例进行操作。我已将我的实现部署为单独的 jar,因此解决方案是:ctx.lookup("java:global.MiBean.NewSessionBean!co.com.tutorial.stateless.NewSessionBeanRemote");
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 2020-12-03
    • 2019-02-05
    相关资源
    最近更新 更多