【问题标题】:Accessing singleton EJB from another webapp in TomEE从 TomEE 中的另一个 Web 应用程序访问单例 EJB
【发布时间】:2011-12-05 23:57:58
【问题描述】:

我在 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.SolverRegistryorg.apache.openejb.core.ivm.IntraVmProxyorg。 apache.openejb.BeanContext$Removable.

为什么这不起作用?

【问题讨论】:

    标签: java singleton openejb apache-tomee


    【解决方案1】:

    我已通过将查找行更改为:

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

    还是不知道openejb:global/global/localhost/SolverCore-1.0/SolverRegistryBean是干什么用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 2015-05-30
      • 1970-01-01
      • 2019-03-14
      • 1970-01-01
      相关资源
      最近更新 更多