Java EE way to ensure initialization of all EAR parts

I am wondering how it would be possible to ensure the launch of the full application without having problems accessing or launching some components of the application.

I am talking about Java EE 6 / Java EE 7 applications that contain several WAR and EJB components. The EAR application contains message-driven beans (launched without external access control), servlets (launched / accessible without user or interface management systems), and TimerEJB, which themselves run according to a specific schedule.

Imagine that when you start an EAR application, you must make sure that the parts of the application must be initialized. For instance. You run tools such as database migration, which can take several hours. How is it possible in Java EE 6 / Java EE 7 to control that none of the above parts of the application can even be executed until init has passed the correct initialization transfer. And if initialization fails, reject operations on any of the services in Java EE?

I hope I explain my problem correctly. In short: how can I execute the "Init" code before any other code in my application is executed? And how can I avoid executing any other code if my "Init" code fails? Is there a standard way of Java EE 6 / Java EE 7? If not, is there a jboss7 / wildfly way?

+4
source share
1 answer

here's how we did it:

for each application / service (ear or war, take your choice), get "startupFinished" @Startup @Singleton. this singleton will depend on all other singletones inside this application - it will be that the singletones that do all the actual init work (and to avoid the lazy link initialization traps, it's best to call some kind of isInitialized () method for all of them) .

all MDBs in the application depend on this StartupFinished singleton application (see this question for what).

( ) - A.ear B.ear A StartupFinished singleton inject B StartupFinished ( @Remote EJB).

, , StartupStarted A, B StartupFinished one - , B , A .

+3

All Articles