【发布时间】:2014-12-08 16:18:25
【问题描述】:
我有一个带有战争 ejb 和耳朵的简单多模块 maven 项目
当我尝试使用查找从 java pojo 类访问我的 ejb 时,它给了我 Wildfly 上的类转换异常,它在 jboss 7 上完美运行..
我已经检查了与这篇文章相关的几乎所有链接,如果有人知道如何解决这个问题,请提供帮助。这是我的示例代码:
我的ejb界面:
package interfacejar;
import javax.ejb.Local;
public interface HelloWorldRemote {
public String sayHello();
public void helloWait() ;
}
会话 Bean
@Stateless
public class HelloWorld implements Serializable, HelloWorldRemote {
public String sayHello() {
// TODO Auto-generated method stub
return "hello";
}
public void helloWait(){
// TODO Auto-generated method stub
System.out.println("in ejb");
}
}
我的战争界面: //因为我正在从我的maven项目的不同模块中的pojo类访问ejb,所以它也需要在这个模块中创建接口
package interfacejar;
public interface HelloWorldRemote {
public String sayHello();
public void helloWait() throws Exception;
}
我的 Java 类
public class Testnew{
public HelloWorldRemote getProps(){
HelloWorldRemote ref=null;
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jboss.as.naming.InitialContextFactory");
props.setProperty("java.naming.provider.url", "localhost");
props.setProperty("jboss.naming.client.ejb.context", "true");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.ejb.client.naming");
Context context = new InitialContext(props);
Object obj = context.lookup("java:global/MyEarFile/testejb-0.0.1-SNAPSHOT/HelloWorld!interfacejar.HelloWorldRemote");
ref=(HelloWorldRemote) obj;
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ref;
}
public void getRemote(){
HelloWorldRemote ref=null;
try {
ref=getProps();
ref.helloWait();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
调用这个类的Servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
this.processRequest(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
this.processRequest(request, response);
}
//java:global/MyEarFile/testejb-0.0.1-SNAPSHOT/HelloWorld!interfacejar.HelloWorldRemote*
/*@Resource(mappedName = "java:global/MyEarFile/tstwar-0.0.1-SNAPSHOT/HelloWorld!interfacejar.HelloWorldRemote")
private HelloWorldRemote helloWorldRemote;*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("in servlet");
Testnew testnew = new Testnew();
testnew.getRemote();
}
这是我遇到的错误
21:06:49,205 ERROR [stderr] (default task-3) java.lang.ClassCastException: interfacejar.HelloWorldRemote$$$view4 cannot be cast to interfacejar.HelloWorldRemote
21:06:49,205 ERROR [stderr] (default task-3) at com.test.Testnew.getProps(Testnew.java:43)
21:06:49,205 ERROR [stderr] (default task-3) at com.test.Testnew.getRemote(Testnew.java:59)
【问题讨论】:
标签: java maven jakarta-ee ejb wildfly-8