javax.naming.NameNotFoundException: While trying t

2020-02-15 03:32发布

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条回答
Root(大扎)
2楼-- · 2020-02-15 04:04

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");
查看更多
登录 后发表回答