使用CGLIB创建对象时,将对象发送为null

时间:2011-08-21 12:36:23

标签: java ejb ejb-3.0 weblogic cglib

我正在创建客户端层中对象(A SERIALIZABLE对象)的代理,并将此对象发送到EJB(在Weblogic 10.3.4服务器上使用EJB 3.0)。在EJB中,参数为null! 我确保我发送的对象在客户端中不为null,并且它是可序列化的(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!

1 个答案:

答案 0 :(得分:0)

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