开机时启动Jersey应用程序运行的初始化代码以初始化应用程序 [英] Jersey app-run initialization code on startup to initialize application

查看:317
本文介绍了开机时启动Jersey应用程序运行的初始化代码以初始化应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Jersey开发的应用程序.我需要通过运行特定于应用程序的登录名/代码在Tomcat 7容器中启动webapp/war时进行一些初始化.

I have an app built with Jersey.I need to do some initialization on startup of the webapp/war in the Tomcat 7 container by running an application specific login/code.

用Jersey做到这一点的最佳方法是什么?在Servlet环境中,我之前已将ContextListener与contextInitialized()一起使用.在进行此呼叫之前,我需要确保加载Jersey资源.

What is the best way to do this with Jersey ? I have used ContextListener with contextInitialized()before in a Servlet environment. I need to make sure the Jersey resources are loaded before I make this call.

推荐答案

不确定"Jersey资源之前已加载"是什么意思,但是如果您想真正插入Jersey的初始化过程,就可以. "插件点(尚未广泛宣传或记录),而我将要描述的内容是在AbstractResourceModel初始化后被调用的-在应用启动后也是如此.

Not sure what you mean by "Jersey resources are loaded before", but if you want to really plug in into Jersey init process.. Jersey has several "monitoring" plugin points (not widely advertised or documented) and what I'm going to describe is being called after initialization of AbstractResourceModel - so right after app startup.

尝试一下:

@Provider
public class Listener implements AbstractResourceModelListener {

    @Override
    public void onLoaded(AbstractResourceModelContext modelContext) {
        System.out.println("##### resource model initiated");
    }
}

在每个应用程序生命周期中应该只发生一次,我不确定是否需要重新加载,但是如果您不使用该功能,则不必费心(无论如何,应在此处进行一些检查,以免发生多次重复加载)调用可能会导致某些问题).

It should happen only once per app lifecycle, I'm not very sure about reloading, but you don't need to bother by it if you are not using that feature (anyway, you should put some check there to avoid multiple invocation if could cause some issues).

这篇关于开机时启动Jersey应用程序运行的初始化代码以初始化应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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