Kein EJB-Empfänger für die Handhabung verfügbar - Java, Java-Ee, Jboss, Ejb, Jndi

Ich lerne, wie man EJBs auf JBoss deployed, indem ich diesen zwei Tutorials folge:

  1. TutorialsPoint
  2. JBoss-Dokumentation

Im Grunde habe ich ein EJB-Projekt namens "EjbComponent" in Netbeans mit diesen beiden Klassen erstellt:

LibrarySessionBeanRemote.java

package com.test.stateless;

import java.util.List;

public interface LibrarySessionBeanRemote {

void addBook(String bookName);

List getBooks();

}

LibrarySessionBean.java

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

Ich stelle sie dann erfolgreich auf JBoss Server bereit

21:16:13,566 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "EjbComponent.jar" (runtime-name: "EjbComponent.jar")
21:16:13,582 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016002: Processing weld deployment EjbComponent.jar
21:16:13,583 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named LibrarySessionBean in deployment unit deployment "EjbComponent.jar" are as follows:

java:global/EjbComponent/LibrarySessionBean!com.test.stateless.LibrarySessionBeanRemote
java:app/EjbComponent/LibrarySessionBean!com.test.stateless.LibrarySessionBeanRemote
java:module/LibrarySessionBean!com.test.stateless.LibrarySessionBeanRemote
java:jboss/exported/EjbComponent/LibrarySessionBean!com.test.stateless.LibrarySessionBeanRemote
java:global/EjbComponent/LibrarySessionBean
java:app/EjbComponent/LibrarySessionBean
java:module/LibrarySessionBean

21:16:13,589 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016005: Starting Services for CDI deployment: EjbComponent.jar
21:16:13,593 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016008: Starting weld service for deployment EjbComponent.jar
21:16:13,735 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS015865: Replaced deployment "EjbComponent.jar" with deployment "EjbComponent.jar"

Um nun dieses EJB zu verwenden, erstelle ich einen eigenständigen Java-Client, indem ich ein anderes Projekt in Netbeans namens "Test" mit einer Klasse erstelle:

EJBTester.java

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

jboss-ejb-client.properties

endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=127.0.0.1
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.default.username=app1
remote.connection.default.password=pass123

Wenn ich versuche, diese Anwendung auszuführen, erhalte ich den folgenden Fehler:

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 [email protected]
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)

Kann mir jemand sagen, wo ich den Fehler mache? Ich habe die anderen Threads auf Stackoverflow gelesen, die das gleiche Problem auflisten, und habe alle ihre Lösungen ausprobiert, einschließlich der folgenden in meinem Code

jndiProperties.put("jboss.naming.client.ejb.context", true);
context.close();

aber immer noch den Fehler bekommen.

Meine Konfigurationsdetails:

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

Antworten:

3 für die Antwort № 1

Ich konnte den Fehler mit einer fehlenden Datei jboss-ejb-client.properties reproduzieren. Stellen Sie sicher, dass es korrekt in Ihrem Projekt platziert ist.

Um es in meinem Fall zu lösen, habe ich es eingefügt:

Java / src

Ich hoffe, das hilft


Speisekarte