从 TomEE 中的另一个 Web 应用程序访问单例 EJB
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将查找行更改为:
仍然不知道 openejb:global/global/localhost/SolverCore-1.0/SolverRegistryBean 的用途来解决我的问题。
I have resolved my problem by changing the lookup line to:
Still don't know what is openejb:global/global/localhost/SolverCore-1.0/SolverRegistryBean for.