gpt4 book ai didi

jakarta-ee - javax.命名.NameNotFoundException : While trying to lookup 'abc' didn't find subcontext 'abc'

转载 作者:行者123 更新时间:2023-12-02 00:28:03 30 4
gpt4 key购买 nike

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

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

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

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");

感谢您考虑我的请求。

附言我正在学习 tutorialspoint 上的 EJB 教程。

最佳答案

你可以在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");

关于jakarta-ee - javax.命名.NameNotFoundException : While trying to lookup 'abc' didn't find subcontext 'abc' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52999407/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com