Java 没有可用于处理的EJB接收器

Java 没有可用于处理的EJB接收器,java,jakarta-ee,jboss,ejb,jndi,Java,Jakarta Ee,Jboss,Ejb,Jndi,我通过以下两个教程学习如何在JBoss上部署EJB: 因此,基本上我在Netbeans中创建了一个名为“EjbComponent”的EJB项目,使用以下两个类: LibrarySessionBeanRemote.java package com.test.stateless; import java.util.List; public interface LibrarySessionBeanRemote { void addBook(String bookName); List ge

我通过以下两个教程学习如何在JBoss上部署EJB:

  • 因此,基本上我在Netbeans中创建了一个名为“EjbComponent”的EJB项目,使用以下两个类:

    LibrarySessionBeanRemote.java

    package com.test.stateless;
    
    import java.util.List;
    
    public interface LibrarySessionBeanRemote {
    
    void addBook(String bookName);
    
    List getBooks();
    
    }
    
    package com.test.stateless;
    
    import java.util.List;
    import java.util.ArrayList;
    import javax.ejb.Stateless;
    import javax.ejb.Remote;
    
    @Stateless
    @Remote(LibrarySessionBeanRemote.class)
    public class LibrarySessionBean implements LibrarySessionBeanRemote {
    
    List<String> bookShelf;
    
    public LibrarySessionBean(){
        bookShelf = new ArrayList<String>();
    }
    
    @Override
    public void addBook(String bookName){
        bookShelf.add(bookName);
    }
    
    @Override
    public List<String> getBooks(){
        return bookShelf;
    }
    }
    
    package com.test.client;
    
    import com.test.stateless.LibrarySessionBeanRemote;
    import com.test.stateless.LibrarySessionBean;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Hashtable;
    import java.util.List;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.security.Security;
    import org.jboss.sasl.JBossSaslProvider;
    
    public class EJBTester {
    
    BufferedReader brConsoleReader = null;
    
    {
        brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
    }
    
    public static void main(String[] args) {
        EJBTester ejbTester = new EJBTester();
        ejbTester.testStatelessEjb();
    }
    
    private void showGUI(){
        System.out.println("*************************");
        System.out.println("Welcome to the Book Store");
        System.out.println("*************************");
        System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice:");
    }
    
    private void testStatelessEjb(){
        try{
            Hashtable jndiProperties = new Hashtable();
            jndiProperties.put("jboss.naming.client.ejb.context", true);
            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            final Context context = new InitialContext(jndiProperties);
            final String appName = "";
            final String moduleName = "EjbComponent";
            final String distinctName = "";
            final String beanName = LibrarySessionBean.class.getSimpleName();
            final String viewClassName = LibrarySessionBeanRemote.class.getName();
            final String lookupPath = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
            LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote)context.lookup(lookupPath);
            System.out.println(lookupPath);
            int choice = 0;
            while (choice != 2) {
                String bookName;
                showGUI();
                String strChoice = brConsoleReader.readLine();
                choice = Integer.parseInt(strChoice);
                if (choice == 1) {
                   System.out.print("Enter book name: ");
                   bookName = brConsoleReader.readLine();
                   libraryBean.addBook(bookName);          
                } else if (choice == 2){
                   break;
                }
            }
            List<String> booksList = libraryBean.getBooks();
            System.out.println("Book(s) entered so far: " + booksList.size());
            for(String book: booksList){
                System.out.println(book);
            }
            System.out.println("**********Using second lookup to get library statless object");
            LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote)context.lookup(lookupPath);
            booksList = libraryBean1.getBooks();
            System.out.println("Book(s) entered so far: " + booksList.size());
            for(String book: booksList){
                System.out.println(book);
            }
            context.close();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(brConsoleReader != null)
                    brConsoleReader.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }    
    }
    
    LibrarySessionBean.java

    package com.test.stateless;
    
    import java.util.List;
    
    public interface LibrarySessionBeanRemote {
    
    void addBook(String bookName);
    
    List getBooks();
    
    }
    
    package com.test.stateless;
    
    import java.util.List;
    import java.util.ArrayList;
    import javax.ejb.Stateless;
    import javax.ejb.Remote;
    
    @Stateless
    @Remote(LibrarySessionBeanRemote.class)
    public class LibrarySessionBean implements LibrarySessionBeanRemote {
    
    List<String> bookShelf;
    
    public LibrarySessionBean(){
        bookShelf = new ArrayList<String>();
    }
    
    @Override
    public void addBook(String bookName){
        bookShelf.add(bookName);
    }
    
    @Override
    public List<String> getBooks(){
        return bookShelf;
    }
    }
    
    package com.test.client;
    
    import com.test.stateless.LibrarySessionBeanRemote;
    import com.test.stateless.LibrarySessionBean;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Hashtable;
    import java.util.List;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.security.Security;
    import org.jboss.sasl.JBossSaslProvider;
    
    public class EJBTester {
    
    BufferedReader brConsoleReader = null;
    
    {
        brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
    }
    
    public static void main(String[] args) {
        EJBTester ejbTester = new EJBTester();
        ejbTester.testStatelessEjb();
    }
    
    private void showGUI(){
        System.out.println("*************************");
        System.out.println("Welcome to the Book Store");
        System.out.println("*************************");
        System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice:");
    }
    
    private void testStatelessEjb(){
        try{
            Hashtable jndiProperties = new Hashtable();
            jndiProperties.put("jboss.naming.client.ejb.context", true);
            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            final Context context = new InitialContext(jndiProperties);
            final String appName = "";
            final String moduleName = "EjbComponent";
            final String distinctName = "";
            final String beanName = LibrarySessionBean.class.getSimpleName();
            final String viewClassName = LibrarySessionBeanRemote.class.getName();
            final String lookupPath = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
            LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote)context.lookup(lookupPath);
            System.out.println(lookupPath);
            int choice = 0;
            while (choice != 2) {
                String bookName;
                showGUI();
                String strChoice = brConsoleReader.readLine();
                choice = Integer.parseInt(strChoice);
                if (choice == 1) {
                   System.out.print("Enter book name: ");
                   bookName = brConsoleReader.readLine();
                   libraryBean.addBook(bookName);          
                } else if (choice == 2){
                   break;
                }
            }
            List<String> booksList = libraryBean.getBooks();
            System.out.println("Book(s) entered so far: " + booksList.size());
            for(String book: booksList){
                System.out.println(book);
            }
            System.out.println("**********Using second lookup to get library statless object");
            LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote)context.lookup(lookupPath);
            booksList = libraryBean1.getBooks();
            System.out.println("Book(s) entered so far: " + booksList.size());
            for(String book: booksList){
                System.out.println(book);
            }
            context.close();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(brConsoleReader != null)
                    brConsoleReader.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }    
    }
    
    现在要使用这个EJB,我通过在Netbeans中创建另一个名为“Test”的项目创建了一个独立的java客户机,该项目包含一个类:

    EJBTester.java

    package com.test.stateless;
    
    import java.util.List;
    
    public interface LibrarySessionBeanRemote {
    
    void addBook(String bookName);
    
    List getBooks();
    
    }
    
    package com.test.stateless;
    
    import java.util.List;
    import java.util.ArrayList;
    import javax.ejb.Stateless;
    import javax.ejb.Remote;
    
    @Stateless
    @Remote(LibrarySessionBeanRemote.class)
    public class LibrarySessionBean implements LibrarySessionBeanRemote {
    
    List<String> bookShelf;
    
    public LibrarySessionBean(){
        bookShelf = new ArrayList<String>();
    }
    
    @Override
    public void addBook(String bookName){
        bookShelf.add(bookName);
    }
    
    @Override
    public List<String> getBooks(){
        return bookShelf;
    }
    }
    
    package com.test.client;
    
    import com.test.stateless.LibrarySessionBeanRemote;
    import com.test.stateless.LibrarySessionBean;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Hashtable;
    import java.util.List;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.security.Security;
    import org.jboss.sasl.JBossSaslProvider;
    
    public class EJBTester {
    
    BufferedReader brConsoleReader = null;
    
    {
        brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
    }
    
    public static void main(String[] args) {
        EJBTester ejbTester = new EJBTester();
        ejbTester.testStatelessEjb();
    }
    
    private void showGUI(){
        System.out.println("*************************");
        System.out.println("Welcome to the Book Store");
        System.out.println("*************************");
        System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice:");
    }
    
    private void testStatelessEjb(){
        try{
            Hashtable jndiProperties = new Hashtable();
            jndiProperties.put("jboss.naming.client.ejb.context", true);
            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            final Context context = new InitialContext(jndiProperties);
            final String appName = "";
            final String moduleName = "EjbComponent";
            final String distinctName = "";
            final String beanName = LibrarySessionBean.class.getSimpleName();
            final String viewClassName = LibrarySessionBeanRemote.class.getName();
            final String lookupPath = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
            LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote)context.lookup(lookupPath);
            System.out.println(lookupPath);
            int choice = 0;
            while (choice != 2) {
                String bookName;
                showGUI();
                String strChoice = brConsoleReader.readLine();
                choice = Integer.parseInt(strChoice);
                if (choice == 1) {
                   System.out.print("Enter book name: ");
                   bookName = brConsoleReader.readLine();
                   libraryBean.addBook(bookName);          
                } else if (choice == 2){
                   break;
                }
            }
            List<String> booksList = libraryBean.getBooks();
            System.out.println("Book(s) entered so far: " + booksList.size());
            for(String book: booksList){
                System.out.println(book);
            }
            System.out.println("**********Using second lookup to get library statless object");
            LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote)context.lookup(lookupPath);
            booksList = libraryBean1.getBooks();
            System.out.println("Book(s) entered so far: " + booksList.size());
            for(String book: booksList){
                System.out.println(book);
            }
            context.close();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(brConsoleReader != null)
                    brConsoleReader.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }    
    }
    
    尝试运行此应用程序时,出现以下错误:

    run:
    Jul 03, 2015 9:28:42 PM org.jboss.ejb.client.EJBClient <clinit>
    INFO: JBoss EJB Client version 1.0.30.Final-redhat-1
    ejb:/EjbComponent//LibrarySessionBean!com.test.stateless.LibrarySessionBeanRemote
    *************************
    Welcome to the Book Store
    *************************
    Options 
    1. Add Book
    2. Exit 
    Enter Choice:1
    Enter book name: abcd
    
    java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EjbComponent, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@7aec35a
         at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:747)
         at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
         at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
         at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
         at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
         at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
         at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
         at com.sun.proxy.$Proxy0.addBook(Unknown Source)
         at com.test.client.EJBTester.testStatelessEjb(EJBTester.java:58)
         at com.test.client.EJBTester.main(EJBTester.java:25)
     BUILD SUCCESSFUL (total time: 7 seconds)
    
    但是仍然得到了错误

    我的配置详细信息:

    • Netbeans IDE 8.0.2
    • JBoss EAP 6.4
    • Java 1.8.0_45
    • Ubuntu 14.04 64位

    我能够用丢失的jboss-ejb-client.properties文件重现错误。确保将其正确放置在项目中

    为了解决我的问题,我将其放入:

    java/src


    希望这有帮助

    请确认您在项目中放置jboss-ejb-client.properties的位置。能够复制丢失的属性文件感谢一吨的Phuthib!它现在对我也很管用。您知道java应用程序只在java/src文件夹中查找jndi.properties文件的原因吗?这是唯一可能的情况还是也可以配置?很高兴我能提供帮助。我的理解是,文件只需要在类路径中就可以工作。您还可以尝试“-Djboss.ejb.client.properties.file.path=/home/me/my client/custom jboss ejb-client.properties”