无法在JBoss 4.2.3中从ServletContextListener查找EJB3

时间:2010-11-28 16:17:04

标签: java servlets jboss ejb jndi

我创建了一个带有本地接口的EJB计时器,我无法通过ServletContextListener对它进行JNDI查找。

以下是EJB代码的一部分:

@Stateless
@LocalBinding(jndiBinding = "TimedFileDeletion")
public class TimedFileDeletionBean implements TimedFileDeletionBeanLocal {

 @Resource
    TimerService timerService;
 private String timerInfo = "FileDeletionTimer";

    public void startTimer() {
    ....
    }

    public boolean isItRunning() {
    ....
    }

    @Timeout
    public void timeout(Timer timer) {
    ....
    }
}

这是本地界面:

public interface TimedFileDeletionBeanLocal {

 public void startTimer();

 public boolean isItRunning();
}

这是ServletContextListener:

public class StartupEventHandler implements ServletContextListener {

 TimedFileDeletionBeanLocal timedFileDeletionBeanLocal;

    public StartupEventHandler() {
     try {
   InitialContext ic = new InitialContext();
   timedFileDeletionBeanLocal = (TimedFileDeletionBeanLocal) ic.lookup("java:comp/env/ejb/TimedFileDeletion");

  } catch (NamingException e) {
   e.printStackTrace();
  }
    }

    public void contextInitialized(ServletContextEvent arg0) {
        if(!timedFileDeletionBeanLocal.isItRunning()) {
         timedFileDeletionBeanLocal.startTimer();
        }
    }

    public void contextDestroyed(ServletContextEvent arg0) {

    }
}

对于查找,我还使用了以下字符串,但没有一个工作: - java:comp / env / TimedFileDeletion - java:comp / TimedFileDeletion - java:TimedFileDeletion - TimedFileDeletion

在所有情况下,我都收到了javax.naming.NameNotFoundException。

任何建议都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

启动JBoss时,它会记录所有本地/远程接口和他们的jndi配置。

JBoss启动日志:

15:26:47,394 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

hrms/AccountSummarySessionBean/local - EJB3.x Default Local Business Interface
hrms/AccountSummarySessionBean/local-com.cc.hrms.bl.accounts.generalaccount.session.AccountSummarySessionBeanLocal - EJB3.x Local Business Interface

查找:

initialCtx.lookup("hrms/AccountSummarySessionBean/local-com.cc.hrms.bl.accounts.generalaccount.session.AccountSummarySessionBeanLocal");

我正在使用JBoss-5&有通用的查找方法,只给出接口名称。

您可以相应地修改它。

相关问题