0

我正在为客户端层中的对象(SERIALIZABLE 对象)创建代理,并将此对象发送到 EJB(在 Weblogic 10.3.4 服务器上使用 EJB 3.0)。在 EJB 中,参数为空!我确保我发送的对象在客户端中不为空,并且它是可序列化的(System.out.println(c instanceof Serializable) 打印为 true)。可能是什么问题呢?

// Creating the proxy
public Object createProxy(Class targetClass)
{
    Enhancer enchancer = new Enhancer();
    enchancer.setSuperclass(targetClass);
    enchancer.setInterfaces(new Class[] { Serializable.class })
    enhancer.setCallback(new LazyInterceptor()); // LazyInterceptor implements Serializable
    return enhancer.create(); 
}

在客户端创建对象:

SomeClass c = new SomeClass(); // SomeClass implements Serializable
getTestService.test(c); // In this call, the parameter in the EJB is **not** null
c = (SomeClass)createProxy(c.getClass());
System.out.println(c instanceof Serializable); // This prints out true
getTestService.test(c); // In this call, the parameter in the EJB is null!
4

1 回答 1

0

Cglib 在增强另一个类时动态创建一个新类。此类可能可以通过接口进行序列化,但在客户端创建时,它在服务器上仍然不可用。事实上,没有 cglib 类实际上是可序列化的,因为它们对于正在运行的 JVM 实例是唯一的。即使您在服务器上执行了相同的增强,类仍然会有所不同。因此,服务器应该抛出 aClassNotFoundException而不是设置null。您可能在容器中发现了一个错误。

于 2013-12-29T01:05:47.467 回答