我在Apache TomEE +上部署了2个Web应用程序。在第一个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 $ Removable。

为什么这不起作用?

最佳答案

我已通过将查找行更改为以下方式解决了我的问题:

SolverRegistry reg = (SolverRegistry)ctx.lookup("SolverRegistryBeanRemote");


仍然不知道openejb:global / global / localhost / SolverCore-1.0 / SolverRegistryBean是什么。

10-04 12:39