Link to home
Start Free TrialLog in
Avatar of NilkanthR
NilkanthR

asked on

How to call Session bean's method at application startup in EJB3?

How to call Session bean's method at application startup in EJB3? I am using EJB 3 and Websphere 7.0. I do not want to use web components like servlet etc.
ASKER CERTIFIED SOLUTION
Avatar of Mr_It
Mr_It

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One way to do this is to add a servlet and in it init look up the ejab and call the method. set the load onstartup variable for the servlet. EJB 3.1(The EJB 3.1 specification is not yet final ), there a type of bean called Singleton. Singletons have an @Startup annotation which can be applied to the bean class. When used, the Container will instantiate the Singleton instance eagerly when the application starts up, otherwise the Container will instantiate the Singleton instance lazily when the bean is first accessed.
Avatar of NilkanthR
NilkanthR

ASKER

My project do not have any web component so I do not want to add servlets just to invoke an EJB.
Websphere startup Beans are based on EJB 2.1 specification. Although we can have EJB2.1 and EJB 3.0 work together, but this will violet specifications of my project.
There is yet another workaround as follows
1) use <start-at-app-start> websphere extention for the session bean. This instructs container to instantiate the sesstion bean when application start.
2) From the construtor of the seesion bean invoke other method.

But this implementation has dependancy on IBM vendor.
I need pure J2EE based solution.
Any help will be appriciated.