部署完成后启动调度程序
我有 Java EE 5 和 Websphere 7.0 上的 webproject 我需要创建调度程序并在部署应用程序后启动它。 我尝试过的: 我使用接口创建 EJB:
@Local
public interface ISchedulerBean {
public void executeTimer(Timer timer);
public void createTimer();
}
无状态会话 bean 实现此接口。 createTimer 方法从 TimerService 创建计时器实例。这部分代码工作正常。 另外,我需要在应用程序部署后调用方法 createTimer() 。 我尝试过:
添加侦听器 servletContext:
公共类 SchedulerInitialiserContextListener 实现 ServletContextListener { //查找ejb的服务 私有 WebServiceLocator webServiceLocator; 私有SchedulerService调度服务;
公共 SchedulerInitialiserContextListener() { webServiceLocator = new WebServiceLocator(); SchedulerService = webServiceLocator.getSchedulerService(); }
public void contextDestroyed(ServletContextEvent ctx) { } 公共无效contextInitialized(ServletContextEvent ctx){ SchedulerService.createTimer(); }
}
- 创建 Servlet,其中在 init() 方法中注入 SchedulerBean 并调用 createTimer。
但这不起作用,因为首先webspere部署Web应用程序,调用侦听器,初始化servlet,然后才部署所有ejb所在的ejb.jar。我可以在 webshpere 日志文件中看到这一点。因此,当我尝试 get ejb throw @EJB 注释或查找时,我得到异常,因为尚未找到 ejb。 可能是在部署 ejb 模块或更改部署顺序后启动计时器的其他方法?
I have webproject on Java EE 5 and Websphere 7.0
I need to create scheduler and start it after deploy application.
What I tried:
I create EJB with interface:
@Local
public interface ISchedulerBean {
public void executeTimer(Timer timer);
public void createTimer();
}
stateless session bean implements this interface. Method createTimer creates timer instance from TimerService. This part of code work fine.
Also I need to call method createTimer() after application deploy.
I tried:
Add listener servletContext:
public class SchedulerInitialiserContextListener implements ServletContextListener {
//service to lookup ejb
private WebServiceLocator webServiceLocator;
private SchedulerService schedulerService;public SchedulerInitialiserContextListener() {
webServiceLocator = new WebServiceLocator();
schedulerService = webServiceLocator.getSchedulerService();
}public void contextDestroyed(ServletContextEvent ctx) { } public void contextInitialized(ServletContextEvent ctx) { schedulerService.createTimer(); }
}
create Servlet with 1 where inject SchedulerBean in init() method and call createTimer.
But this does not work, because at first webspere deploy web application, call listeners, initialize servlets, and only then deploy ejb.jar in which all ejb are located. I can see that in webshpere log file. So when I try get ejb throw @EJB annotation or lookup I get Exception, beacause ejb has not been found.
May be is other approach to start timer after deploy ejb module or change deploy order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以设置模块的启动顺序。
假设您使用 Rational Application Developer 进行开发,请执行以下操作:
右键单击您的 Ear 项目,然后单击 Java EE ->打开WebSphere 应用程序服务器部署。
查找“应用程序”部分,您将看到所有模块,并且可以为每个模块设置
起始重量
。确保包含上下文侦听器的 Web 项目具有最大值,这样应该没问题。
You can set the startup order of your modules.
Assuming you develop with Rational Application Developer do the following:
Right click your ear project and click Java EE -> Open WebSphere Application Server Deployment.
Look for the Application section, you will see all the modules and you can set the
Start weight
for each one.Make sure your web project containing the Context Listener has the largest value an you should be fine.