EJB (EAR) Architektur

G

Gast2

Gast
Hallo zusammen,

ich habe ein EJB-Modul Projekt mit einem Service:

Java:
@Stateful
@Remote
public class HelloWorldImpl implements HelloWorld{


    
    @Override
    public String sayHello(){
	System.out.println("hello world");
	return "hello world";
    }
}

Dieses Projekt nutzt ein ejb-commons in welchem die ganzen Interfaces drin.
Java:
public interface HelloWorld{

    public String sayHello();
}

Mein Richt Client Projekt nutzt natürlich diese commons auch.
Java:
public class Client {

	public static void main(String[] args) throws Exception{

		//RMI
		Hashtable<String,String> environment = new Hashtable<String,String>();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        environment.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); // remote machine IP
        Context context = new InitialContext(environment);
    	try {
    		HellorWorld hello = (HellorWorld ) context
			.lookup("HelloWorldImpl/remote");
			hello.sayHello();
		} catch (NamingException e) {
			e.printStackTrace();
		}	
    

	}
}


Bekomme ich immer die Fehlermeldung
Java:
Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to service.PricepilotSession
	at main.Client.main(Client.java:22)

Das passiert nur wenn ich ein Projekt verwende welches der Server und der Client benutzt. Ich habe gelesen die Exception kommt wenn der Server und Client unterschiedeliche jars benutzt, was bei mir ja nicht sein kann weil ich auf die Projekt Referenzen gehe.

Ist an der Architektur was falsche?
ejb-commons -->interfaces
client benutzt ejb-commons
ejb-module (bu) benutzt ejb-commons
 

FArt

Top Contributor
Ich bin mir nicht sicher was passiert, wenn man an der Implementierung lediglich die @Remote Annotation hinschreibt, ohne das Businessinterface in dieser Annotation zu konfigurieren.

Ich würde in dieser Reihenfolge den Fehler suchen:
1.) Ist der Code sauber? Wohl nicht, denn was ist PricepilotSession, welches in deinem Beispiel nicht vorkommt.
2.) Nutzt der Client die gleichen Client JARs (auch die Clientressourcen des Applikationsservers). Gehe nicht nach "kann nicht sein" sondern kontrolliere das!
3.) Annotiere die Implementierung mit @Remote(HelloWorld.class)
 

fastjack

Top Contributor
Wenn Du in der Annotation nix bei Remote angibst, wird in diesem Fall "HelloWorld" als Remote-Interface benutzt.

Wenn Du in der Annotation ein Interface angibst, wird dieses als Remote-Interface benutzt.
 
G

Gast2

Gast
Immer noch gleiches Problem
Java:
@Stateful
@Remote(HelloWorld.class)
public class HelloWorldImpl implements HelloWorld{


    
    @Override
    public String sayHello(){
	System.out.println("hello world");
	return "hello world";
    }
}

Java:
public interface HelloWorld{

    public String sayHello();
}

Java:
public class Client {

	public static void main(String[] args) throws Exception{

		//RMI
		Hashtable<String,String> environment = new Hashtable<String,String>();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        environment.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); // remote machine IP
        Context context = new InitialContext(environment);
    	try {
    		HellorWorld hello = (HellorWorld ) context
			.lookup("HelloWorldImpl/remote");
			hello.sayHello();
		} catch (NamingException e) {
			e.printStackTrace();
		}	
    

	}
}


Java:
Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to service.HelloWorld
	at main.Client.main(Client.java:22)
 
G

Gast2

Gast
Okay hab jetzt mal alle jboss/client jars(ca. 40 stück) genommen und im client aufgenommen dann hat es getan
 
Ähnliche Java Themen

Ähnliche Java Themen

Neue Themen


Oben