我正在學習如何通過以下兩個教程在JBoss部署EJB的EJB接收器:沒有可用於處理
所以基本上我創建了一個名爲的EJB項目「 EjbComponent「在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服務器成功
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,我通過創建另一個創建一個獨立的Java客戶端在Netbeans項目中稱爲「Test」的一類:
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 [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)
誰能告訴我我犯了什麼錯誤?我讀過關於計算器其他線程上市了同樣的問題,並試圖像包括在我的代碼
jndiProperties.put("jboss.naming.client.ejb.context", true);
context.close();
,但仍然得到錯誤下面的所有解決方案。
我的配置詳情:
- NetBeans IDE的8.0.2
- 的JBoss EAP 6.4
- 的Java 1.8.0_45
- 的Ubuntu 14.04 64位
請確認凡在你的項目中,你放在jboss-ejb-client.properties 。能夠重現與缺少的屬性文件 – Phuthib