【问题标题】:Cannot lookup EJB3 from ServletContextListener in JBoss 4.2.3无法从 JBoss 4.2.3 中的 ServletContextListener 查找 EJB3
【发布时间】:2010-11-28 16:17:03
【问题描述】:

我创建了一个带有本地接口的 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 - 定时文件删除

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

任何建议将不胜感激。

【问题讨论】:

    标签: java servlets jboss ejb jndi


    【解决方案1】:

    在启动 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 并且有通用的查找方法,只是给出接口名称。

    您可以进行相应的修改。

    【讨论】:

    • 非常感谢。我在日志中查找了该名称,使用了它有效的名称。
    猜你喜欢
    • 2018-04-08
    • 2012-05-28
    • 2011-01-22
    • 2011-11-15
    • 2016-01-10
    • 1970-01-01
    • 2018-09-13
    • 2011-08-08
    • 1970-01-01
    相关资源
    最近更新 更多