2017-01-18 5 views
0

Я сделал проект EJB в NetBeans 8.2 с wildfly 10.1.Ошибка проекта EJB: javax.naming.NameNotFoundException

Я создал два проекта для этого: EJBComponent (LibrarySessionBean.java, LibrarySessionBeanRemote.java) и EjbTester (EJBTester.java)

ошибки, когда я пытаюсь запустить EJBTester.java:

run: 
sty 18, 2017 3:13:55 PM org.xnio.Xnio <clinit> 
INFO: XNIO version 3.4.0.Final 
sty 18, 2017 3:13:55 PM org.xnio.nio.NioXnio <clinit> 
INFO: XNIO NIO Implementation Version 3.4.0.Final 
sty 18, 2017 3:13:55 PM org.jboss.remoting3.EndpointImpl <clinit> 
INFO: JBoss Remoting version 4.0.21.Final 
sty 18, 2017 3:13:56 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage 
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river] 
sty 18, 2017 3:13:56 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate 
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{[email protected], receiver=Remoting connection EJB receiver [connection=Remoting connection <5fc52344> on endpoint "config-based-naming-client-endpoint" <13a5fe33>,channel=jboss.ejb,nodename=lenovo-g580]} on channel Channel ID 8f1e528b (outbound) of Remoting connection 3701eaf6 to localhost/127.0.0.1:8080 of endpoint "config-based-naming-client-endpoint" <13a5fe33> 
ejb:/EJBComponent//LibrarySessionBean!com.ejb.stateless.LibrarySessionBeanRemote -- service jboss.naming.context.java.jboss.exported.ejb:.EJBComponent."LibrarySessionBean!com.ejb.stateless.LibrarySessionBeanRemote" 
javax.naming.NameNotFoundException: ejb:/EJBComponent//LibrarySessionBean!com.ejb.stateless.LibrarySessionBeanRemote -- service jboss.naming.context.java.jboss.exported.ejb:.EJBComponent."LibrarySessionBean!com.ejb.stateless.LibrarySessionBeanRemote" 
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106) 
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207) 
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184) 
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127) 
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
BUILD SUCCESSFUL (total time: 1 second) 

Мой код:

LibrarySessionBean.java

package com.ejb.stateless; 

import java.util.ArrayList; 
import java.util.List; 
import javax.ejb.Remote; 
import javax.ejb.Stateless; 

@Stateless 
@Remote(LibrarySessionBeanRemote.class) 
public class LibrarySessionBean implements LibrarySessionBeanRemote { 

    List<String> bookShelf;  

    public LibrarySessionBean(){ 
     bookShelf = new ArrayList<>(); 
    } 

    @Override 
    public void addBook(String bookName) { 
     bookShelf.add(bookName); 
    }  

    @Override 
    public List<String> getBooks() { 
     return bookShelf; 
    } 
} 

LibrarySessionBeanRemote.java

package com.ejb.stateless; 

import java.util.List; 
import javax.ejb.Remote; 

@Remote 
public interface LibrarySessionBeanRemote { 

    void addBook(String bookName); 

    List getBooks(); 

} 

Приложение для клиентов, выполненное в разных проектах.

EJBTester.java

package com.ejb.test; 

import com.ejb.stateless.LibrarySessionBean; 
import com.ejb.stateless.LibrarySessionBeanRemote; 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.List; 
import java.util.Properties; 
import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

public class EJBTester { 

    BufferedReader brConsoleReader = null; 
    Properties props; 
    InitialContext ctx; 

    final String appName = ""; 
    final String moduleName = "EJBComponent"; 
    final String distinctName = ""; 
    final String beanName = LibrarySessionBean.class.getSimpleName(); 
    final String viewClassName = LibrarySessionBeanRemote.class.getName(); 

    { 
     props = new Properties(); 
     props.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName()); 

     props.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); //http-remoting://127.0.0.1:8080 
//  props.put(Context.SECURITY_PRINCIPAL, "testuser"); 
//  props.put(Context.SECURITY_CREDENTIALS, "test"); 
     props.put("jboss.naming.client.ejb.context", true); 

    try { 
     ctx = new InitialContext(props); 
    } catch (NamingException ex) { 

     ex.printStackTrace(); 
    } 

     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 Book Store"); 
     System.out.println("**********************"); 
     System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice: "); 
    } 

    private void testStatelessEjb(){ 


     try { 
     int choice = 1; 
     LibrarySessionBeanRemote libraryBean = 
     (LibrarySessionBeanRemote)ctx.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName); 

     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 (int i = 0; i < booksList.size(); ++i) { 
     System.out.println((i+1)+". " + booksList.get(i)); 
     } 

     LibrarySessionBeanRemote libraryBean1 = 
     (LibrarySessionBeanRemote)ctx.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName); 

     List<String> booksList1 = libraryBean1.getBooks(); 
     System.out.println(
     "***Using second lookup to get library stateless object***"); 
     System.out.println(
     "Book(s) entered so far: " + booksList1.size()); 

     for (int i = 0; i < booksList1.size(); ++i) { 
      System.out.println((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()); 
     } 
     } 
    } 
} 

ответ

1

Изменить код, чтобы соответствовать, что объясняется здесь: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Проверьте, правильно ли "JBoss-EJB-client.jar" доступна в клиентском пути к классам?

+0

Я прочитал этот сайт, но все еще придерживался своего примера. В моем проекте клиента у меня есть путь к классам: jboss-cli-client.jar, jboss-client.jar (они из wildfly) и EJBComponent.jar – twistezo

+0

Есть ли у вас какие-либо следы на стороне сервера? – ehsavoie

Смежные вопросы