从 TomEE 中的另一个 Web 应用程序访问单例 EJB

发布于 2024-12-20 01:57:03 字数 1718 浏览 3 评论 0原文

我在 Apache TomEE+ 上部署了 2 个 Web 应用程序。在第一个 web 应用程序中,我创建了一个单例 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。

为什么这不起作用?

I have 2 webapps deployed on Apache TomEE+. In the first webapp I have created a singleton EJB class declared like this:

@Singleton
@Remote
@Startup
@Lock(READ)
public class SolverRegistryBean implements SolverRegistry
{
    // ...

From openejb.log I can see, that the singleton is available:

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)

From my other app I want to access that singleton bean, so I do:

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");

but then I get ClassCastException

java.lang.ClassCastException: $Proxy94 cannot be cast to grid.solver.SolverRegistry

I checked that this $Proxy94 class implements interfaces: grid.solver.SolverRegistry, org.apache.openejb.core.ivm.IntraVmProxy and org.apache.openejb.BeanContext$Removable.

Why this doesn't work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2024-12-27 01:57:03

我通过将查找行更改为:

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

仍然不知道 openejb:global/global/localhost/SolverCore-1.0/SolverRegistryBean 的用途来解决我的问题。

I have resolved my problem by changing the lookup line to:

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

Still don't know what is openejb:global/global/localhost/SolverCore-1.0/SolverRegistryBean for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文