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

混江龙づ霸主 提交于 2019-12-02 08:33:49

问题


I've developed a EJB application, with a Remote interface. This application was deployed on weblogic 12.

With a java application, i'm trying use my EJB application, but when I call method lookup from the class InitialContext, i get this message "javax.naming.NameNotFoundException: While trying to lookup 'NewSessionBean.remote' didn't find subcontext 'NewSessionBean"

This is code from remote 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();
}

This is part of the code from implementation:

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>();
    }

And this is a part of the code when i call lookup:

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

Thanks for considering my request.

PS I am following the EJB tutorial at tutorialspoint.


回答1:


You could see your JNDI tree through the following path in Weblogic's console

Environment -> servers -> select your server -> click on view JNDI tree link

I always check JNDI tree for lookup problems.

Why do not you use JNDI portable name for lookup?

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

If you had deployed your implementation as a separate EAR, you could use the following lookup

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

If you had deployed your implementation as a separate jar, you could use the following lookup

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

If you want to look up in the same EAR but in a different jar

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

If you want to look up in the same EAR and in the same jar

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


来源:https://stackoverflow.com/questions/52999407/javax-naming-namenotfoundexception-while-trying-to-lookup-abc-didnt-find-sub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!