无法从 JBoss 4.2.3 中的 ServletContextListener 查找 EJB3

发布于 2024-10-05 00:57:42 字数 1585 浏览 3 评论 0原文

我创建了一个具有本地接口的 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。

任何建议将不胜感激。

I have created an EJB timer with a local interface and I am not able to do JNDI lookup for it from a ServletContextListener.

Here is part of the EJB code:

@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) {
    ....
    }
}

Here is the local interface:

public interface TimedFileDeletionBeanLocal {

 public void startTimer();

 public boolean isItRunning();
}

And here is the 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) {

    }
}

For the lookup I also used the following Strings but none of the worked:
- java:comp/env/TimedFileDeletion
- java:comp/TimedFileDeletion
- java:TimedFileDeletion
- TimedFileDeletion

In all cases I was getting a javax.naming.NameNotFoundException.

Any advice would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2024-10-12 00:57:42

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

您可以相应地修改它。

While starting JBoss it logs all the local/remote interfaces & their jndi configuration.

JBoss startup log :

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

Lookup :

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

I am using JBoss-5 & have generalized method for lookup, just giving interface name.

You can modify it accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文