我正在学习如何通过以下两个教程在JBoss上部署EJB:
所以基本上我创建了一个名为" EjbComponent"的EJB项目。在Netbeans中有这两个类:
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;
}
}
然后我成功将它们部署到JBoss Server
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"
现在使用这个EJB,我通过在Netbeans中创建另一个名为&#34; Test&#34;的项目来创建一个独立的Java客户端。一节课:
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 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();
}
}
}
}
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
当我尝试运行此应用程序时,出现以下错误:
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)
有谁能告诉我我在哪里弄错了?我已经阅读了stackoverflow上列出相同问题的其他线程,并尝试了所有解决方案,例如在我的代码中包含以下内容
jndiProperties.put("jboss.naming.client.ejb.context", true);
context.close();
但仍然收到错误。
我的配置详情:
答案 0 :(得分:3)
我能够使用缺少的jboss-ejb-client.properties文件重现错误。确保将其正确放置在项目中。
要解决我的问题,我将其放入:
的java / SRC
希望有所帮助