Well, I'm using Quartz to schedule some jobs that I need in my application. But, I need some way to access a Stateful SessionBean on my Job. I knew that I can't inject it with @EJB. Can anyone help me? Thanks.
How to access EJB from a Quartz Job
8.7k views Asked by Fernando Camargo At
3
There are 3 answers
0
On
you can do that simply by lookup the EJB via JNDI in the Job implementation. In particular, the JNDI name will be:
mappedName#name_of_businessInterface
where name_of_businessInterface
is the fully qualified name of the business interface of this session bean. For example, if you specify mappedName="bank"
and the fully qualified name of the business interface is com.CheckingAccount
, then the JNDI of the business interface is bank#com.CheckingAccount
.
Code Example:
Context context = new InitialContext();
MyService myService= (MyService) context.lookup("MyService#com.test.IMyService");
I used the EJB3InvokerJob to invoke the methods of my EJB. Then I created my jobs that extends the EJB3InvokerJob, put the parameters of what EJB and method it should call and then call the super.execute().
The EJB3InvokerJob can be found here: http://jira.opensymphony.com/secure/attachment/13356/EJB3InvokerJob.java
My Job is looking like this:
And my EJB is like this:
I expect to help someone.