在开发 Java EE 应用程序时,我经常遇到在应用程序启动、停止等时执行操作的“问题”。例如,对于 Weblogic,有一种机制(应用程序生命周期侦听器)。但如果你想让你的应用程序免受应用程序的影响。服务器特定,您必须找到不同的解决方案。有些人建议使用启动时加载的 servlet,并“滥用”init()
/destroy()
。
其他人说使用 ServletContextListener。对我来说,最后一个听起来最好(根据 ServletContextListener
不幸的是,今天我尝试了 JBoss 7,其中似乎 jax-ws webservices 在任何其他 Servlet
之前初始化,因此,在 ServletContextListener 收到通知之前
- 我只是在这里面临一些应用程序服务器特定问题 - 或者是否有任何“更合适”的标准化 Java EE 方法来注册事物、执行操作,在任何 web 服务、servlet 等初始化之前?
When developing an Java EE Application, I often came across the 'problem' to do stuff when the application is started, stopped etc. Now for Weblogic for example, there is a mechanism for that (the application life-cycle listener). But if you want to keep your application free from stuff that is app. server specific, you have to find a different solution. Some recommend using a servlet that is loaded on start-up, and "abuse" the init()
/destroy()
.
Others say use a ServletContextListener
. To me, the last one sounds best (according to the java doc for ServletContextListener
. Unfortunately, today I tried JBoss 7, where it seems that jax-ws webservices are initialized before any other Servlet
, thus before the ServletContextListener
gets a notification.
Long story short - am I just facing some app server specific issues here - or is there any "more appropriate", standardized Java EE way to register things, do stuff, before any webservice, servlet, whatsoever is initialized?
发布评论
评论(2)
如果您的 Web 服务是这样注释的,
那么它们还不是真正的 servlet,但是 JBoss (Jax-WS) 会将它们变成一个启动项。
我正在使用 jboss-4.2.3,并且在调用 ServletContextListner 之前我也会收到这些消息。
但我想知道,这个 Web 服务在完整的应用程序启动之前是否可用,因为几乎在部署结束时我收到以下消息
所以我猜测,这是一个与 jboss 相关的问题。也许我们应该在另一个应用程序服务器上进行测试来证明这一点。
If your webservices are annotated like this
they are no real servlets yet, but JBoss (Jax-WS) will turn them into a startup.
I am using jboss-4.2.3 and I am also getting these messages before my
ServletContextListner
is called.But I wonder, if this webservice is available before the complete application has started because nearly at the end of deployment I get following messages
So I would guess, that this is a jboss related issue. Maybe we should test on another app server to proof so.
我使用 Java EE 8 API 在 WebLogic 14 上使用以下 bean 完成了此操作,
我在运行时遇到了与 OP 相同的问题,并且我正在寻找将我的代码与特定于供应商的库分离的方法。
按照注释,并在 Maven 上找到的
javax:javaee-api
的帮助下,我取代了 WebLogic 的ApplicationLifecycleListener
,从而删除了 POM 和所有其余部分的依赖关系它带来的问题。我希望这也适用于 JBoss。
I did it with the following bean on WebLogic 14 with Java EE 8 API
I had the same problem as the OP with my runtime, and I was looking for decouple my code from vendor-specific libraries.
Following the comments, and with the help of
javax:javaee-api
which can be found on Maven I superseded WebLogic'sApplicationLifecycleListener
thus removing the dependency from the POM and all the rest of the problems it takes along.I would expect this to work on JBoss too.