我的应用程序启动后如何加载/初始化我的类?
我们有一个在 Websphere 上运行的 Java 应用程序。我有一个类,我希望在 Websphere 加载时立即加载并初始化,或者在 Websphere 中重新加载应用程序时立即加载和初始化,而无需等待第一个网页加载。我很确定将它加载到我们的 HttpServlet 子类中可能是错误的地方。那么什么是正确的地方呢?
We have a Java app that runs on Websphere. I have one class that I want to load and initialize as soon as Websphere loads, or as soon as the app is reloaded within Websphere, without waiting for the first web page to be loaded. I'm pretty sure loading it in our subclass of HttpServlet is probably the wrong place. So what is the right place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你想要一个 ServletContextListener。
在此之前,人们实际上会将此类代码放入 Servlet 中(不一定映射到任何 url),并在初始化时加载它。但 ServletContextListener 现在是正确的方法。
像这样进入 web.xml:
I think you want a ServletContextListener.
Before that was available, people would actually put this kind of code into a Servlet (not necessarily mapped to any url), and have that loaded on initialization. But ServletContextListener is the proper way now.
Goes into web.xml like this:
正如 Thilo 提到的,ServletContextListeners 对于 Web 应用程序很有用。
如果您的应用程序不使用 Web 组件,那么您也可能会考虑 WebSphere 特定的扩展 - StartUp Beans。
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/asyncbns/任务/tasb_confstb.html
HTH
曼鲁
As Thilo mentioned ServletContextListeners are good for Web Applications.
If your application does not use the Web Components then you could possibly be looking at WebSphere specific extensions too - StartUp Beans.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/asyncbns/tasks/tasb_confstb.html
HTH
Manglu