javax.naming.NameNotFoundException:尝试查找 'abc' 时未找到子上下文 'abc'

javax.naming.NameNotFoundException: While trying to lookup 'abc' didn't find subcontext 'abc'

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

对于 java 应用程序,我正在尝试使用我的 EJB 应用程序,但是当我从 class InitialContext 调用方法查找时,我收到此消息 "javax.naming.NameNotFoundException: While trying to lookup 'NewSessionBean.remote' didn't find subcontext '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 教程。

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

环境 -> 服务器 -> select 你的服务器 -> 点击查看 JNDI 树 link

我总是检查 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");