Java 使用抽象参数远程调用ejb方法
远程调用带有在客户端上扩展的参数的ejb方法会导致ClassNotFoundException 例如:Java 使用抽象参数远程调用ejb方法,java,ejb-3.0,Java,Ejb 3.0,远程调用带有在客户端上扩展的参数的ejb方法会导致ClassNotFoundException 例如: @Stateless public class EjbService implements EjbServiceRemote { public void doSth(SomeAbstractClass sac) { //do sth with sac } } @Remote public interface EjbServiceRemote { pub
@Stateless
public class EjbService implements EjbServiceRemote {
public void doSth(SomeAbstractClass sac) {
//do sth with sac
}
}
@Remote
public interface EjbServiceRemote {
public void doSth(SomeAbstractClass sac);
}
package com.simple;
public class SimpleEJBTestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
EjbServiceRemote ejbRemote = //lookup stuff
SomeAbstractClass sac = new SomeAbstractClass {}; //extend it
ejbRemote.doSth(sac); //results in ClassNotFound
}
}
例外情况:
Servlet.service() for servlet SimpleEJBTestServlet threw exception: java.lang.RuntimeException: JBAS014154: Failed to marshal EJB parameters
java.lang.ClassNotFoundException: com.simple.SimpleEJBTestServlet$1 from [Module "deployment.simpleEjbService.ear.simpleEjb:main" from Service Module Loader]
SomeAbstractClass位于客户端和远程应用程序的类路径中,但它们使用不同的类加载器加载(显然)
这种行为是预期的还是我遗漏了什么?我怎么解决这个案子
java.lang.ClassNotFoundException:com.simple.SimpleEJBTestServlet$1
匿名实现类SimpleEJBTestServlet$1仅对服务器已知,而对客户端未知
双方必须了解所有参数、返回和异常类型。不可能序列化另一方不知道的内容(包括子类),因为对于Reomte EJB,只有内容(对象)被序列化,而不是类本身
我建议将它们保存在一个单独的JAR中,您可以在客户端和服务器项目之间共享。但是我通过序列化发送的“东西”是一些抽象类,它位于远程和客户端应用程序的类路径中。为什么我在客户机上如何扩展或实现它很重要?不,您发送的对象具有具体的动态类型(动态静态类型)。客户端对象的运行时动态类型应该是什么?一个对象不能有抽象类型…那么它意味着:1)我不能使用接口或抽象类作为ejb方法参数,或者2)我必须与远程应用程序共享客户端实现细节,这与它们无关。使用接口和抽象类参数指定远程方法是绝对正确的。但是双方都必须知道在它们之间交换对象的所有实现类。我建议3)使这些实现类不受客户端/服务器端代码的影响。@Reek:这也包括子类。我建议对它们进行重构,并消除您想要在客户机和服务器之间序列化的任何对象中的JSF依赖关系。