我在Apache TomEE +上部署了2个webapps。在第一个webapp中,我创建了一个单独的EJB类,声明如下:
@Singleton
@Remote
@Startup
@Lock(READ)
public class SolverRegistryBean implements SolverRegistry
{
// ...
从openejb.log我可以看到,单身人士可用:
2011-12-05 20:43:22,696 - INFO - Jndi(name=SolverRegistryBeanRemote) --> Ejb(deployment-id=SolverRegistryBean)
2011-12-05 20:43:22,696 - INFO - Jndi(name=global/localhost/SolverCore-1.0/SolverRegistryBean!grid.solver.SolverRegistry) --> Ejb(deployment-id=SolverRegistryBean)
2011-12-05 20:43:22,696 - INFO - Jndi(name=global/localhost/SolverCore-1.0/SolverRegistryBean) --> Ejb(deployment-id=SolverRegistryBean)
2011-12-05 20:43:22,750 - INFO - Started Ejb(deployment-id=SolverRegistryBean, ejb-name=SolverRegistryBean, container=My Singleton Container)
从我的其他应用程序中我想访问该单例bean,所以我这样做:
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
p.put("java.naming.provider.url", "http://127.0.0.1:8080/openejb/ejb");
try {
ctx = new InitialContext(p);
SolverRegistry reg = (SolverRegistry)ctx.lookup(
"openejb:global/global/localhost/SolverCore-1.0/SolverRegistryBean");
然后我得到ClassCastException
java.lang.ClassCastException: $Proxy94 cannot be cast to grid.solver.SolverRegistry
我检查了这个$ Proxy94类实现了接口: grid.solver.SolverRegistry , org.apache.openejb.core.ivm.IntraVmProxy 和 org。 apache.openejb.BeanContext $可拆卸
为什么这不起作用?
答案 0 :(得分:2)
我通过将查询行更改为:
解决了我的问题SolverRegistry reg = (SolverRegistry)ctx.lookup("SolverRegistryBeanRemote");
仍然不知道什么是 openejb:global / global / localhost / SolverCore-1.0 / SolverRegistryBean for。