远程调用带有在客户端结果上扩展的参数的 ejb 方法,并出现 ClassNotFoundException。
例如:
@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
}
}
异常(exception):
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 中,您可以在客户端和服务器项目之间共享该 JAR。
关于java - 使用抽象参数远程调用 ejb 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31650673/