Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Application Level Initialization

 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,
I am facing an issue in my design of my application and struggling to get a robust solution for it.
To lay it down in simple terms i have an EAR which has currently 1 war and 1 ejb jar. I am expecting my EAR to scale up in near time,
where i will be having few more wars and business components added. Currently i am using a ServletContextListener to do all the application level initialization.
But then later noticed that it is not a correct solution as i don't want to depend on sequence of servlet's startups (from different wars).
There should be some standardized solution which allows me to do initialization at application level. In simple terms i want to execute some piece of code(at EAR level)
before any other code gets executed.


Regards,
Shroff.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Shroff wrote:
But then later noticed that it is not a correct solution as i don't want to depend on sequence of servlet's startups (from different wars).


You can use initialize-in-order within the application.xml and then list the war modules in the right order and have the initialization done in the first listed war.
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:
You can use initialize-in-order within the application.xml and then list the war modules in the right order and have the initialization done in the first listed war.

Yeah thats what i am backing on currently, just wanted to know if this is the only standard way ?


Regards,
Shroff.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a bean annotated with @Singleton and @Startup? You still don't have full control over the startup order if you use other mechanisms (like ServletContextListener), but at least you can use @DependsOn to specify that these beans should be loaded after another. For instance:
You can now know for sure that these three beans are loaded at startup in order MyBean1, MyBean2, MyBean3.
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:How about a bean annotated with @Singleton and @Startup? You still don't have full control over the startup order if you use other mechanisms (like ServletContextListener), but at least you can use @DependsOn to specify that these beans should be loaded after another.


Thanks. Actually i was trying to figure out whether there is any way i can achieve to put all my initialization code in ear project. But then reading through articles i realized that ear core objective is packaging of application.


Regards,
Shroff.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic