2016-07-31 49 views
0

umgewandelt werden Ich habe ein Stateless Projekt EJB (Helloworld) unter Wildfly ausgeführt 8.2.1 Final Server mit Java 1.7 und eine Client-App mit Java 1.8. Ich erhalte einen Fehler. Dankejava.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext kann nicht in

Exception in thread "main" java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext kann nicht auf com.aburak.sb.SessionBeanRemote bei com gegossen werden. aburak.sb.Driver.main (Driver.java:15)

dies ist mein Treiberklasse, die Client-Anwendung

public class Driver { 
    public static void main(String[] args) throws NamingException { 
      Context context=Driver.getInitialContext(); 
      SessionBeanRemote sbRemote= (SessionBeanRemote) context.lookup("ejb:SessionBean/SessionBean!com.aburak.sb.SessionBeanRemote"); 
      sbRemote.sessionBeanMethod(); 
    } 
    public static Context getInitialContext() throws NamingException{ 
     Properties properties = new Properties(); 
     properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
     properties.setProperty(Context.PROVIDER_URL, "http://127.0.0.1:8080"); 

     return new InitialContext(properties); 
    } 
} 

Fern BeanSession

ist
@Stateless 
@TransactionManagement(TransactionManagementType.BEAN) 
public class SessionBean implements SessionBeanRemote, SessionBeanLocal{ 

private static final long serialVersionUID = -7201692010023776738L; 

@Override 
public void sessionBeanMethod() { 
    System.out.println("SessionBean executed..."); 

} 

SessionBeanRemote

@Remote 
public interface SessionBeanRemote extends SessionBeanIF{ 

} 

(SessionBeanLocal ist genau die gleiche SessionBeanRemote außer @Local Anmerkung)

SessionBeanIF

public interface SessionBeanIF extends Serializable{ 
public void sessionBeanMethod(); 
} 

und dies ist die Client-Laufwerk Klasse

public class Driver { 
    public static void main(String[] args) throws NamingException { 
      Context context=Driver.getInitialContext(); 
      SessionBeanRemote sbRemote= (SessionBeanRemote) context.lookup("ejb:SessionBean/SessionBean!com.aburak.sb.SessionBeanRemote"); 
      sbRemote.sessionBeanMethod(); 
    } 
    public static Context getInitialContext() throws NamingException{ 
     Properties properties = new Properties(); 
     properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
     properties.setProperty(Context.PROVIDER_URL, "http://127.0.0.1:8080"); 

     return new InitialContext(properties); 
    } 
} 

SessionBeanClient >> pom.xml

<dependencies> 
    <dependency> 
     <groupId>org.wildfly</groupId> 
     <artifactId>wildfly-ejb-client-bom</artifactId> 
     <version>8.2.1.Final</version> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>org.wildfly</groupId> 
     <artifactId>wildfly-jms-client-bom</artifactId> 
     <version>8.2.1.Final</version> 
     <type>pom</type> 
    </dependency> 
</dependencies> 

SessionBean >> pom.xml

<dependency> 
    <groupId>javax.ejb</groupId> 
    <artifactId>javax.ejb-api</artifactId> 
    <version>3.2</version> 
    <scope>compile</scope> 
</dependency> 

Ich folge this tutorial video aber ich etwas App-Server ändern usw. und auch der Fehler this finden suchen, aber es hat mein Problem nicht gelöst.

Das ist meine Package explorer

Dank vier Ihre Hilfe.

Antwort

0

Ihr Pfad für den Remoteaufruf ist falsch. Sehen Sie sich den vollständigen Pfad im Serverprotokoll an, wenn Sie den ejb auf den Server von wildfly implementieren. Es wird aussehen wie

ejb:/ejb-1.0-SNAPSHOT/SessionBean!com.thanhnn.training.SessionBeanRemote 

Sie eine Eigenschaft Datei benötigen in Ressourcen-Ordner des Client mit dem Namen ‚jboss-ejb-client.properties‘.

remote.connections=default 
remote.connection.default.host=localhost 
remote.connection.default.port=8080 
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false 
remote.connection.default.username=your-user-name 
remote.connection.default.password=your-pass-word 

Um eine Anwendung Benutzer, führen Add-user.bat oder add-user.sh in $ {JBOSS_HOME}/bin, und folgen Sie den Prozess zu erstellen.

Für den Handshake-Prozess von Client und Server, müssen Sie die folgenden Abhängigkeiten in pom-Datei:

<dependency> 
     <groupId>org.jboss.spec.javax.transaction</groupId> 
     <artifactId>jboss-transaction-api_1.2_spec</artifactId> 
     <version>1.0.1.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.spec.javax.ejb</groupId> 
     <artifactId>jboss-ejb-api_3.2_spec</artifactId> 
     <version>1.0.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss</groupId> 
     <artifactId>jboss-ejb-client</artifactId> 
     <version>2.1.6.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.xnio</groupId> 
     <artifactId>xnio-api</artifactId> 
     <version>3.4.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.xnio</groupId> 
     <artifactId>xnio-nio</artifactId> 
     <version>3.4.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.remoting</groupId> 
     <artifactId>jboss-remoting</artifactId> 
     <version>4.0.21.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.sasl</groupId> 
     <artifactId>jboss-sasl</artifactId> 
     <version>1.0.5.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.marshalling</groupId> 
     <artifactId>jboss-marshalling-river</artifactId> 
     <version>1.4.11.Final</version> 
    </dependency> 

Und schließlich, den Code für die Client-

public static void main(String[] args) throws NamingException { 
    Context context=Driver.getInitialContext(); 
    SessionBeanRemote sbRemote= (SessionBeanRemote) context.lookup("ejb:/ejb-1.0-SNAPSHOT/SessionBean!com.thanhnn.training.SessionBeanRemote"); 
    sbRemote.sessionBeanMethod(); 
} 
public static Context getInitialContext() throws NamingException{ 
    Properties properties = new Properties(); 
    properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 

    return new InitialContext(properties); 
} 

Hinweis: Sie müssen nicht die Methode als öffentlich in der Schnittstelle

zu deklarieren