How WebSphere manages startup order of EJB jars?

2019-07-21 11:08发布

问题:

When an ear would contain two ejb modules modulea.jar and moduleb.jar. And modulea.jar contains an @Startup ejbX, that calls another ejbY, which is not an @Startup ejb, from moduleb.jar during the startup of the bean X it is required that moduleb.jar is started first as otherwise the app server is not able to inject X into Y. But how to ensure that moduleb.jar is started first?

Currently I have this problem in WebSphere, but I can't seem to find a way to enforce an order. Is there something in the spec to manage order?

Or maybe WebSphere specific (rather not have vendor lock in though). Maybe it is a poor design to have a startup ejb and an ejb that is used by it in different modules, some insight about that is also welcome.

回答1:

It is possible to configure it via Starting weight in the module configuration (Enterprise Applications > YourApplication > Manage Modules > ejbmoduleb.jar)

Starting weight

Specifies the order in which modules are started when the server starts. The module with the lowest starting weight is started first.

If you need order dependency among whole applications, you set Startup order in the Startup behavior application configuration (Enterprise Applications > YourApplication > Startup behavior)

Startup order

Specifies the order in which applications are started when the server starts. The startup order is like a starting weight. The application with the lowest starting weight is started first.

If you plan to have application.xml deployment descriptor add the following entry to the descriptor and provide modules in the correct order.

<initialize-in-order>true</initialize-in-order>

See also:

  • EJB module settings
  • Application startup behavior