java.lang.ClassCastException:$ Proxy99无法强制转换 [英] java.lang.ClassCastException: $Proxy99 cannot be cast
问题描述
我正在使用JBoss4.2.2和java6。
I am using JBoss4.2.2 and java6.
部署的耳朵的名字是apa.ear
The deployed ear's name is apa.ear
在servlet中,我有以下代码行:
In a servlet I have the following code line:
placeBid = (PlaceBid) context.lookup("apa/"
+ PlaceBid.class.getSimpleName() + "/remote");
我有一个生成的jboss-app.xml,如下所示:
I have a generated jboss-app.xml like this:
<jboss-app>
<loader-repository>apa:app=ejb3</loader-repository>
</jboss-app>
当尝试通过上下文获取PlaceBid时,我得到此异常
When trying to get the PlaceBid via the context I get this exception
java.lang.ClassCastException: $Proxy99 cannot be cast to se.nextit.actionbazaar.buslogic.PlaceBid
PlaceBid界面如下所示:
The PlaceBid interface looks like this:
@Remote
public interface PlaceBid {
Long addBid(String userId, Long itemId, Double bidPrice);
}
当我运行EJB3的实例时,它可以工作。 EJB3在动作示例代码中附带了ant构建。我想使用Maven,所以我重新安排了一些代码。
When I run the example coming with EJB3 in action it works. EJB3 in action sample code comes with ant building. I want to use Maven so I have rearranged the code some.
但是,我不知道我在这里做错了什么。我对jboss-app.xml文件有一些想法。我不确定它的内容应该是什么样的。
However, I don't understan what I am doing wrong here. I have some thoughts about the jboss-app.xml file. I am not sure of how its content should look like.
感谢任何帮助。
祝福Lasse
推荐答案
首先,尝试以下方法:
Object obj = context.lookup("apa/" + PlaceBid.class.getSimpleName() + "/remote");
System.out.println("Object = " + obj.getClass().getName());
System.out.println("Interfaces = " + Arrays.toString(obj.getClass().getInterfaces()));
它将告诉你实际的stub具体类是什么以及它实现了什么接口。这可能会给你足够的暗示来解决出错的问题。
It will tell you what the actual stub concrete class is and what interfaces it implements. This may then give you enough of a hint to work out what's going wrong.
也可能是你的bean被定义为:
Also presumably your bean is defined as:
@Stateless
public class MyPlaceBidBean implements PlaceBid {
...
}
即它实现 PlaceBid
界面?
这篇关于java.lang.ClassCastException:$ Proxy99无法强制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!