【问题标题】:Startup scheduler after compleate deploying完成部署后启动调度程序
【发布时间】:2012-01-17 09:30:09
【问题描述】:

我在 Java EE 5 和 Websphere 7.0 上有 webproject 我需要创建调度程序并在部署应用程序后启动它。 我尝试了什么: 我用接口创建 EJB:

@Local
public interface ISchedulerBean {

    public void executeTimer(Timer timer);
    public void createTimer();
}

无状态会话 bean 实现了这个接口。方法 createTimer 从 TimerService 创建计时器实例。这部分代码工作正常。 我还需要在应用程序部署后调用方法 createTimer()。 我试过了:

  1. 添加监听器servletContext:

    公共类 SchedulerInitialiserContextListener 实现 ServletContextListener { //查找ejb的服务 私有WebServiceLocator webServiceLocator; 私有SchedulerService schedulerService;

    公共 SchedulerInitialiserContextListener() { webServiceLocator = new WebServiceLocator(); schedulerService = webServiceLocator.getSchedulerService(); }

    public void contextDestroyed(ServletContextEvent ctx) {
    }
    
    public void contextInitialized(ServletContextEvent ctx) {
        schedulerService.createTimer();
    }
    

    }

  2. 使用 1 创建 Servlet,其中在 init() 方法中注入 SchedulerBean 并调用 createTimer。

但这不起作用,因为首先 webspere 部署 web 应用程序,调用侦听器,初始化 servlet,然后才部署所有 ejb 所在的 ejb.jar。我可以在 webshpere 日志文件中看到这一点。因此,当我尝试 get ejb throw @EJB annotation 或查找时,我得到 Exception,因为 ejb 尚未找到。 可能是在部署 ejb 模块或更改部署顺序后启动计时器的其他方法吗?

【问题讨论】:

    标签: java deployment scheduler websphere-7


    【解决方案1】:

    您可以设置模块的启动顺序。

    假设您使用 Rational Application Developer 进行开发,请执行以下操作:

    右键单击您的 ear 项目,然后单击 Java EE -> 打开 WebSphere Application Server Deployment。

    查找应用程序部分,您将看到所有模块,您可以为每个模块设置Start weight

    确保包含 Context Listener 的 Web 项目具有最大值,这样就可以了。

    • 此操作会在您的 ear 项目的 META-INF 下创建一个 ibmconfig 目录,请确保您在构建过程中将其打包

    【讨论】:

    • 谢谢!你的回答帮助了我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2020-08-18
    • 1970-01-01
    相关资源
    最近更新 更多