在上一篇博客介绍了如何使用使用Eclipse+JBOSS创建第一个EJB项目,在这期间就遇到一个错误:
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to com.tgb.ejb.HelloWorldBean at com.tgb.ejb.client.Client.main(Client.java:12)
出现的原因有二:
1.你的HelloWroldBean没有显示HelloWrold接口
@Stateless
@Remote({HelloWorld.class})
public class HelloWorldBean implements HelloWorld {
}
2.将从EJB容器中获取的代理对象转为接口
HelloWorld ejb = (HelloWorld) initialContext
.lookup("HelloWorldBean/remote");