Java EE 企业应用程序:在部署/启动时执行一些操作 [英] Java EE Enterprise Application: perform some action on deploy/startup

查看:20
本文介绍了Java EE 企业应用程序:在部署/启动时执行一些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序(具有业务逻辑、EJB 和客户端、Web 的企业应用程序)部署后立即执行一些操作.例如,我想让某个实体处于持久状态,或者以其他方式创建一个文件.我该怎么做?

I would like to perform some action as soon as my application (Enterprise Application with Business Logic, EJB, and a Client, Web) is deployed. For example I would like to make some entity in a persistent state, or otherwise create a file. How can I do that?

谢谢.

推荐答案

配置 SerlvetContextListener 并覆盖 contextInitilized()

在您的 Web 应用程序描述中,web.xml

in your web application description , web.xml

<web-app ...>
    <listener>
        <listener-class>com.someCompany.AppNameServletContextListener</listener-class>
    </listener>
</web-app

<小时>

package com.someCompany;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class AppNameServletContextListener implements ServletContextListener{

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("ServletContextListener destroyed");
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("ServletContextListener started");   
                // do the things here 
    }
}

这篇关于Java EE 企业应用程序:在部署/启动时执行一些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆