Jersey 应用程序在启动时运行初始化代码以初始化应用程序
我有一个用 Jersey 构建的应用程序。我需要在 Tomcat 7 容器中的 webapp/war 启动时通过运行应用程序特定的登录/代码来进行一些初始化。
使用 Jersey 执行此操作的最佳方法是什么?我之前在 Servlet 环境中使用过 ContextListener 和 contextInitialized() 。我需要确保在进行此调用之前加载 Jersey 资源。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定“Jersey 资源之前已加载”是什么意思,但如果您想真正插入 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.
Try this:
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 2.x,您可以执行以下操作:
For Jersey 2.x you can do the following: