无法找到使用InitialContext.lookup(我的豆)方法 [英] cannot find my bean using the InitialContext.lookup() method

查看:1436
本文介绍了无法找到使用InitialContext.lookup(我的豆)方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试使用Struts 1.3 API,使与EJB 3.0的小应用程序。可惜的是我不能使用@EJB注释从我的动作类中调用我的bean对象。我一直在使用不同的解决方法解决了这个问题(第一个是用我的bean我的全局JNDI名称,另一种是首先调用另一个类并从该类使用@EJB注解)。尽管如此,这些两种解决方法有显著的缺点。我想直接从我的动作类叫我的EJB。我已阅读使用的java:c​​omp / env的/ beanName很多例子JNDI名称,但还没有弄清楚如何做到这一点,并得到找不到名称axception。
让本地EJB类的全名是com.ejb.myEjbPackage.MyEJBLocal,我怎么可以调用它使用上下文查找? (我可以做到这一点,而不会修改web.xml和sun-web.xml中描述的?)
我使用的GlassFish服务器和NetBeans IDE。

I have tried to use struts 1.3 API to make a small application with EJB 3.0. Unfortunatelly i cannot use the @EJB annotation to call my bean object from inside my action class. I have solved this problem using different workarounds ( the first one is to use my global jndi name of my bean and the other is to call another class first and use the @EJB annotation from that class). Still these two workarounds have significant disadvantages. I would like to call my EJB directly from my action class. I have read plenty examples using the "java:comp/env/beanName" JNDI name but still haven't figure out how to do it and get name not found axception. Let the full name of the local EJB class be the com.ejb.myEjbPackage.MyEJBLocal, how can i call it using the context lookup? (can i do it without modifying any of the web.xml and sun-web.xml descriptors?) I am using glassfish server and Netbeans IDE.

感谢您提前

推荐答案

我找到了答案:
如果你不能在类中使用EJB注解要再调用这个bean:
如果你不想使用XML描述符乱来定义你的bean,你必须这样做,在bean类本身。
因此,我用下面的注释中GameBean类

I found the answer : If you cannot use the EJB annotation in the class you want to call the bean then : If you don't want to mess with XML descriptors to define your bean , you have to do it in the bean class itself. Hence i used the following annotation in the GameBean class

     @Stateless
     @EJB(name="ejb/GameBean",beanInterface=GameBeanLocal.class,beanName="GameBean")
     public class GameBean implements GameBeanLocal {.....

的beanName是可选的。注释必须在该行上述类的声明进行声明。
然后,为了从其他类调用豆可以执行

The beanName is optional. The annotation must be declared in the line ABOVE the declaration of the class. Then, in order to call the bean from the other class you can do

     InitialContext ic = new InitialContext();
     ic.lookup("java:comp/env/ejb/GameBean");

这篇关于无法找到使用InitialContext.lookup(我的豆)方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆