我一直绞尽脑汁,把谷歌颠倒过来,但无法找到解决这个问题的方法。我使用netbeans 8.1和wildfly 10服务器
这是我的客户端类:
public class EjbTester {
BufferedReader brConsoleReader = null;
Properties props;
InitialContext ctx;
Context remoteContext;
public static void main(String[] args) {
EjbTester ejbtester = new EjbTester();
ejbtester.tasteStatelessEJB();
}
private void tasteStatelessEJB(){
try{
props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://localhost:8050");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put(Context.SECURITY_PRINCIPAL, "steinacoz");
props.put(Context.SECURITY_CREDENTIALS, "nkenna007");
props.put("jboss.naming.client.ejb.context", true);
ctx = new InitialContext(props);
}catch(NamingException ex){
ex.printStackTrace();
}
brConsoleReader = new BufferedReader(new InputStreamReader(System.in));
try{
int choice = 1;
LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote) ctx.lookup("ejb:/EJBtut/LibrarySessionBean!tut.LibrarySessionBeanRemote");
while(choice != 2){
String bookName;
String strChoice = brConsoleReader.readLine();
choice = Integer.parseInt(strChoice);
if(choice == 1){
System.out.println("Enter Book Name: ");
bookName = brConsoleReader.readLine();
libraryBean.addBook(bookName);
}else if(choice == 2){
break;
}
}
List<String> booksList = libraryBean.getBooks();
System.out.println("Books entered so far: " + booksList.size());
for(int i = 0; i < booksList.size(); i++){
System.out.print((i+1) + "." + booksList.get(i));
}
ctx.close();
LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote) ctx.lookup("ejb:/EJBtut/LibrarySessionBean!tut.LibrarySessionBeanRemote");
List<String> booksList1 = libraryBean.getBooks();
System.out.print("---using lookups to get library stateless objects--");
System.out.print("Books Entered so far: " + booksList1.size());
for(int i = 0; i < booksList1.size(); i++){
System.out.print((i+1) + "." + booksList1.get(i));
}
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}finally{
try{
if(brConsoleReader != null){
brConsoleReader.close();
}
}catch(IOException ex){
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
}
}
这是我的远程界面
@Remote
public interface LibrarySessionBeanRemote {
void addBook (String book);
List getBooks();
}
这是我的SessionBean
@Stateless
public class LibrarySessionBean implements LibrarySessionBeanRemote{
List<String> bookShelf;
public LibrarySessionBean() {
bookShelf = new ArrayList<String>();
}
public void addBook(String bookName) {
bookShelf.add(bookName);
}
public List<String> getBooks() {
return bookShelf;
}
}
这是我遇到的错误,有些人应该请帮助
EJBCLIENT000025:没有EJB接收器可用于处理调用上下文的[appName:,moduleName:EJBtut,distinctName:]组合org.jboss.ejb.client.EJBClientInvocationContext@100fc185 java.lang.IllegalStateException:EJBCLIENT000025:没有EJB接收器可用于处理调用上下文的[appName:,moduleName:EJBtut,distinctName:]组合org.jboss.ejb.client.EJBClientInvocationContext@100fc185 在org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) 在org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186) at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255) 在org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200) 在org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183) 在org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146) 在com.sun.proxy。$ Proxy2.addBook(未知来源) at client.EjbTester.tasteStatelessEJB(EjbTester.java:80) 在client.EjbTester.main(EjbTester.java:46)