EJB学习(三)——java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to..

    在上一篇博客介绍了怎样使用使用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");


原文地址:https://www.cnblogs.com/mfmdaoyou/p/6812653.html