EJB 客户端 returns $Proxy119 对象而不是实际 class 对象的上下文查找
Context lookup for EJB client returns $Proxy119 object instead of actual class object
我只是在 JBoss 中像这样调用 EJB 3.0:
MyEJB myEJB = (MyEJB) initialContext.lookup("");
现在查找工作正常。返回的对象具有预期的 viewType、moduleName、beanName。但它抛出这个异常:
2015-04-10 18:49:08,266 ERROR [org.teiid.CONNECTOR] (Worker0_QueryProcessorQueue1128) Connector worker process failed for atomic-request=GfxN/Obks1QK.1.1.0: java.lang.ClassCastException: com.sun.proxy.$Proxy119 cannot be cast to com.MyEJB
如何将其转换为我打算使用的对象?
这是一个代码示例:
HelloLocalHome helloHome;
HelloLocal hello;
//In your main or init method,
// 1. Retreive the Home Interface using a JNDI Lookup
// Retrieve the initial context for JNDI.
// No properties needed when local
Context context = new InitialContext();
// Retrieve the home interface using a JNDI lookup using
// the java:comp/env bean environment variable
// specified in web.xml
helloHome = (HelloLocalHome) context.lookup("java:comp/env/ejb/HelloBean");
//2. Narrow the returned object to be an HelloHome object.
// Since the client is local, cast it to the correct object type.
//3. Create the local Hello bean instance, return the reference
hello = (HelloLocal)helloHome.create();
//And the call will be as follows :
hello.sayHello("James Earl")
原来正确的做法是这样的:
StatelessEJBLocator<MyEjb> locator = new StatelessEJBLocator(
MyEjb.class, APP_NAME, MODULE_NAME,
MyEjbRemote.class.getSimpleName(), DISTINCT_NAME);
MyEjb myEjb = org.jboss.ejb.client.EJBClient.createProxy(locator);
我只是在 JBoss 中像这样调用 EJB 3.0:
MyEJB myEJB = (MyEJB) initialContext.lookup("");
现在查找工作正常。返回的对象具有预期的 viewType、moduleName、beanName。但它抛出这个异常:
2015-04-10 18:49:08,266 ERROR [org.teiid.CONNECTOR] (Worker0_QueryProcessorQueue1128) Connector worker process failed for atomic-request=GfxN/Obks1QK.1.1.0: java.lang.ClassCastException: com.sun.proxy.$Proxy119 cannot be cast to com.MyEJB
如何将其转换为我打算使用的对象?
这是一个代码示例:
HelloLocalHome helloHome;
HelloLocal hello;
//In your main or init method,
// 1. Retreive the Home Interface using a JNDI Lookup
// Retrieve the initial context for JNDI.
// No properties needed when local
Context context = new InitialContext();
// Retrieve the home interface using a JNDI lookup using
// the java:comp/env bean environment variable
// specified in web.xml
helloHome = (HelloLocalHome) context.lookup("java:comp/env/ejb/HelloBean");
//2. Narrow the returned object to be an HelloHome object.
// Since the client is local, cast it to the correct object type.
//3. Create the local Hello bean instance, return the reference
hello = (HelloLocal)helloHome.create();
//And the call will be as follows :
hello.sayHello("James Earl")
原来正确的做法是这样的:
StatelessEJBLocator<MyEjb> locator = new StatelessEJBLocator(
MyEjb.class, APP_NAME, MODULE_NAME,
MyEjbRemote.class.getSimpleName(), DISTINCT_NAME);
MyEjb myEjb = org.jboss.ejb.client.EJBClient.createProxy(locator);