Glassfish 上 EAR 文件内 EJB3 的 JNDI 查找
我有一个 EAR 文件,其中包含一堆 JAR,其中一个 JAR 包含本地会话 Bean (EJB3)。我需要从非托管 POJO 中执行这些会话 Bean 的 JNDI 查找,该 POJO 也包含在 EAR 中(在本例中也包含在与 EJB 相同的 JAR 中)。我尝试遵循 Glassfish EJB FAQ,但我继续无论我尝试什么,都会收到 javax.naming.NameNotFoundException 。
我不确定一些事情。我应该将 ejb-jar.xml 放在哪里(我尝试了 EAR META-INF 以及 JAR META-INF)?我需要 sun-ejb-jar.xml 吗? ejb-link 到底是什么,它有什么作用?我可能做错了什么(我的配置几乎与本地查找常见问题解答中给出的配置相同)?
我列出了我尝试过的一些配置和结果如下:
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<ejb-class>com.test.TestBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
<local>com.test.ITestBean</local>
</ejb-local-ref>
</session>
</enterprise-beans>
应用程序已部署,但 JNDI 查找返回 null。
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<ejb-class>com.test.TestBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
<local>com.test.ITestBean</local>
<ejb-link>ITestBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
应用程序未部署:无法确定 EJB 3.0 的本地业务与远程业务指定ref 未解析的 Ejb-Ref ITestBean@jndi。
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<ejb-class>com.test.TestBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
<local>com.test.ITestBean</local>
<ejb-link>MyJar.jar#ITestBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
应用程序未部署:错误:未解析:MyJar.jar#ITestBean。
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<local>com.test.ITestBean</local>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
</ejb-local-ref>
</session>
</enterprise-beans>
处理 EjbDescriptor 时出错
I have an EAR file with a bunch of JARs in it, and one of these JARs contains Local Session Beans (EJB3). I need to perform a JNDI lookup of these Session Beans from within an unmanaged POJO, also contained in the EAR (and in this case in the same JAR as the EJBs as well). I tried following the Glassfish EJB FAQ, but I keep on receiving a javax.naming.NameNotFoundException no matter what I try.
I am unsure of a few things. Where should I put my ejb-jar.xml (I tried the EARs META-INF as well as the JARs META-INF)? Do I need a sun-ejb-jar.xml? What exactly is ejb-link, what does it do? What could I be doing wrong (my configuration is almost identical to the one given in the FAQ for local lookups)?
I list some of the configuration I tried and the result below:
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<ejb-class>com.test.TestBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
<local>com.test.ITestBean</local>
</ejb-local-ref>
</session>
</enterprise-beans>
Application deploys but JNDI lookup returns null.
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<ejb-class>com.test.TestBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
<local>com.test.ITestBean</local>
<ejb-link>ITestBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
Application doesn't deploy: Unable to determine local business vs. remote business designation for EJB 3.0 ref Unresolved Ejb-Ref ITestBean@jndi.
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<ejb-class>com.test.TestBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
<local>com.test.ITestBean</local>
<ejb-link>MyJar.jar#ITestBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
Application doesn't deploy: Error: Unresolved : MyJar.jar#ITestBean.
<enterprise-beans>
<session>
<ejb-name>ITestBean</ejb-name>
<local>com.test.ITestBean</local>
<ejb-local-ref>
<ejb-ref-name>ITestBean</ejb-ref-name>
</ejb-local-ref>
</session>
</enterprise-beans>
Error processing EjbDescriptor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您还可以随时在 System.out 上转储或在日志中转储 InitialContext 中的所有名称。
You can always also dump on System.out or in a log all the names in the InitialContext.
ejb 文件的 ejb-jar.xml 进入 META-INF(EJB-Jar 的,而不是 Ear 的)。部署描述符中的 EJB 引用看起来像这样:
查找代码看起来像这样:
我不认为您需要容器特定的部署描述符 (sun-ejb-jar.xml) 来进行这种类型的查找。
ejb-jar.xml for your ejb file goes into META-INF (of the EJB-Jar, not of the ear). EJB Refs in the deployment descriptor look something like this:
The lookup code looks something like:
I don't believe that you will need a container specific deployment descriptor (sun-ejb-jar.xml) for this type of lookup.
我认为 EJB 3 可移植性问题 博客文章应该对您有所帮助。
I think the EJB 3 Portability Issue blog post should help you.
不可能从 POJO 执行 Bean 的 JNDI 查找,除非从托管类(例如会话 Bean)调用(直接或间接)该 POJO。换句话说,第一个示例将不起作用,而第二个示例将起作用(假设 MyPOJO 是尝试执行 JNDI 查找的类):
1) UnmanagementClass1 ->非托管类2 ->非托管类3 ->我的POJO
2) 托管类->非托管类2 ->非托管类3 ->我的POJO
It isn't possible to perform a JNDI lookup of a bean from a POJO, unless that POJO is called (directly or indirectly) from a managed class (such as a session bean). In other words, the first example won't work while the second one will (assuming MyPOJO is the class that tries to perform a JNDI lookup):
1) UnmanagedClass1 -> UnmanagedClass2 -> UnmanagedClass3 -> MyPOJO
2) ManagedClass -> UnmanagedClass2 -> UnmanagedClass3 -> MyPOJO
我正在研究 glassfish v2,当从 EJB3 调用 JSNI 时,我只需要 ejb-jar.xml,而不是 sun-ejb-jar.xml
在 TestBean1 内调用服务定位器
将返回 Test2Bean
I have working on glassfish v2 and when calling JSNI from EJB3 I need only ejb-jar.xml, not sun-ejb-jar.xml
Calling the service locator inside TestBean1 as
will return Test2Bean