java 使用@ejb 注释进行远程查找
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16515453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remote lookup using @ejb annotation
提问by JavaGeek
I have 2 servers instances of Jboss 5, each of which is deployed with two EAR's. Say Client.Ear and Server.Ear. Server Ear expose some ejb's. I want to inject this to ClientEar via annotation. Using JNDI lookup i did it fine and it works. But using annotation i always get javax.naming.NamingException. However when injecting session beans accross deployment artifacts the global JNDI name has to be used for injection and i used that also like @EJB(mappedName ="java:global/Server/component/ApplicationService!com.test.server.ApplicationServiceInterface")
我有 2 个 Jboss 5 服务器实例,每个实例都部署了两个 EAR。说 Client.Ear 和 Server.Ear。Server Ear 暴露了一些 ejb。我想通过注释将其注入 ClientEar。使用 JNDI 查找我做得很好,而且工作正常。但是使用注释我总是得到 javax.naming.NamingException。但是,当跨部署工件注入会话 bean 时,必须使用全局 JNDI 名称进行注入,我也使用它,例如 @EJB(mappedName ="java:global/Server/component/ApplicationService!com.test.server.ApplicationServiceInterface")
But it seems like I am not providing the provider_url of the remote server to bound it to the client ear instance. How could i configure jndi properties, ie provider_url, initial context properites with the annotation @ EJB?
但似乎我没有提供远程服务器的 provider_url 来将其绑定到客户端 Ear 实例。我如何配置 jndi 属性,即 provider_url,带有 @EJB 注释的初始上下文属性?
回答by rodrigo.botti
I found a forum post that answers your question: https://community.jboss.org/thread/228789
我找到了一个回答你问题的论坛帖子:https: //community.jboss.org/thread/228789
In it he refers to https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance
在其中他指的是 https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance
And to accomplish the jndi lookup with the @EJB annotaion he uses
并使用他使用的@EJB annotaion 完成 jndi 查找
@EJB(lookup = "ejb:earname/modulename/BeanClass!fully.qualified.RemoteInterface")
private RemoteInterface bean;
回答by Sudhakar
I know this little too late . Including this for further reference
我知道这有点太晚了。包括这个以供进一步参考
You can use the portable look up String format EJBs use RMI over IIOP and has standard mapping EJB architecture to CORBA So you can lookup by server host and portnumber by
您可以使用可移植的查找字符串格式 EJB 在 IIOP 上使用 RMI 并且具有标准的 EJB 体系结构映射到 CORBA 因此您可以通过服务器主机和端口号查找
@EJB(lookup = "corbaname:iiop:example.com:3701#java:global/mycrud/mycrud-dss-ejb/InformeBean!com.myorg.ejb.InformeRemote")
References: https://docs.oracle.com/javase/8/docs/technotes/guides/idl/corba.htmlhttps://docs.oracle.com/javase/8/docs/technotes/guides/idl/INStutorial.html
参考资料:https: //docs.oracle.com/javase/8/docs/technotes/guides/idl/corba.html https://docs.oracle.com/javase/8/docs/technotes/guides/idl/INStutorial .html
回答by Ravi Trivedi
@EJB
annotation can only be used if the applications are deployed in the same sever instance. @EJB
annotation won't work if you are trying to make cross server instance call or remote server call. So, in your case, annotation injection won't work.
@EJB
只有在应用程序部署在同一个服务器实例中时才能使用注解。@EJB
如果您尝试进行跨服务器实例调用或远程服务器调用,则注释将不起作用。因此,在您的情况下,注释注入将不起作用。
So, what are the solutions ?
那么,有哪些解决方法呢?
Option 1)Use old style programmatic JNDI look up
选项 1)使用旧式编程 JNDI 查找
Option 2)Create managed bean as per CDI (Context Dependency Injection)
and configure all the JNDI properties there. And @inject
the managed bean
into your client.
选项 2) 按照创建托管 beanCDI (Context Dependency Injection)
并在那里配置所有 JNDI 属性。而@inject
在managed bean
到您的客户端。