Hello All!
I'm trying to develop a sample application using EJB3.
application has been deployed successfully...no problem with that.
But, when i try to call bean from my client code im getting following exception.
Exception in
thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.kalki.session.MyBeanRemote
at com.kalki.session.MyBeanclient.main(MyBeanclient.java:28)
Here's is my complete code.
Super interface--->IMyBean
package com.kalki.session;
import java.io.Serializable;
public interface IMyBean extends Serializable{
public void show();
}
---------------------------------
Remote Interface----->>MyBeanRemote
package com.kalki.session;
import javax.ejb.Remote;
@Remote
public interface MyBeanRemote extends IMyBean{
}
---------------------------------------
Local Interface--->MyBeanLocal
package com.kalki.session;
import javax.ejb.Local;
@Local
public interface MyBeanLocal extends IMyBean{
}
--------------------------------------------
Session Bean---MyBean
package com.kalki.session;
import javax.ejb.Stateless;
@Stateless
public class MyBean implements MyBeanLocal, MyBeanRemote {
public void show()
{
System.out.println("Hi how are you");
}
}
----------------------------------------------
Client Class---->MyBeanclient
package com.kalki.session;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class MyBeanclient {
/**
* @param args
*/
public static void main(
String[] args) {
try {
Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context context;
context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
I googled for solution but it is of no help.
Please help me.
Thanks in advance,
Anil