• Post Reply Bookmark Topic Watch Topic
  • New Topic

global initialization for all EJB  RSS feed

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is something in JSP world which EJB does not have, one of them is a place for initialization before any EJB runs.

Servlet has that via a ServletContextListener, in which I can place code and store objects as attributes so that they are available to all servlets and JSPs in my web app. That is done before ANY servlet runs. This could be useful for a global object like DataSource reference, etc.

I do not find such equivalence in EJB world, there is no global EJBContext object like the global ServletContext. And there is not a place for a global initialization before EJB runs.

What are the reasons that EJB does not have that?

Thanks.
Yan
 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is what I thought,

Servlet and JSP can make up a real Web Application.

EJBs by themselves donot make up a real app., and therefore the things apply to an app. does not apply to EJB, after all, EJBs are all about components.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36456
460
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yan,
EJBs could be the only J2EE components in an app though. You could have an application client or just make remote calls.

In this case, you would use a static variable in a class or better yet, a singleton for those global resources. It would be initialized on first access.
 
Saulius Sinkunas
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. The big difference is that web app is application and EJB is just component. EJBs should be less coupled as possible. Think about EJB as some module which does it own job. Of cource, you can have references to other EJBs or resources. But if you created some related context, they wuold be very coupled which is bad.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!