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

che*_*nio 1 ejb weblogic jakarta-ee

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

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

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

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();
}
Run Code Online (Sandbox Code Playgroud)

这是实现代码的一部分:

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>();
    }
Run Code Online (Sandbox Code Playgroud)

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

 try {
         int choice = 1; 
         NewSessionBeanRemote  libraryBean = 
         (NewSessionBeanRemote)ctx.lookup("NewSessionBean/remote");
Run Code Online (Sandbox Code Playgroud)

感谢您考虑我的要求。

PS我正在tutorialspoint上关注EJB教程。

Meh*_*hmi 5

您可以通过 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");
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

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

ctx.lookup("java:module//NewSessionBean!co.com.tutorial.stateless.NewSessionBeanRemote");
Run Code Online (Sandbox Code Playgroud)