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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.