无法从 JBoss 4.2.3 中的 ServletContextListener 查找 EJB3
我创建了一个具有本地接口的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
启动 JBoss 时,它会记录所有本地/远程接口和日志。他们的 jndi 配置。
JBoss 启动日志:
查找:
我正在使用 JBoss-5 &有通用的查找方法,只需给出接口名称。
您可以相应地修改它。
While starting JBoss it logs all the local/remote interfaces & their jndi configuration.
JBoss startup log :
Lookup :
I am using JBoss-5 & have generalized method for lookup, just giving interface name.
You can modify it accordingly.