如何从 Quartz 作业访问 EJB
嗯,我正在使用 Quartz 来安排我的应用程序中需要的一些作业。但是,我需要某种方法来访问我的作业中的 Stateful SessionBean。我知道我不能用@EJB 注入它。谁能帮助我吗? 谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用 EJB3InvokerJob 来调用 EJB 的方法。然后我创建了扩展 EJB3InvokerJob 的作业,输入它应该调用的 EJB 和方法的参数,然后调用 super.execute()。
EJB3InvokerJob 可以在这里找到: http://jira.opensymphony.com/secure/ Attachment/13356/EJB3InvokerJob.java
我的工作是这样的:
我的 EJB 是这样的:
我希望能帮助某人。
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.
一个简单的解决方案是在作业实现中通过 JNDI 查找 EJB。
我已经在 Glassfish 3.1 上开发的当前应用程序中完成了此操作。
A simple solution would be to lookup the EJB via JNDI in the Job implementation.
I have done this in a current application I am developing on Glassfish 3.1.
您只需在作业实现中通过 JNDI 查找 EJB 即可做到这一点。特别是,JNDI 名称将为:
其中
name_of_businessInterface
是该会话 bean 的业务接口的完全限定名称。例如,如果您指定mappedName="bank"
并且业务接口的完全限定名称为com.CheckingAccount
,则业务接口的 JNDI 为银行#com.CheckingAccount
。代码示例:
you can do that simply by lookup the EJB via JNDI in the Job implementation. In particular, the JNDI name will be:
where
name_of_businessInterface
is the fully qualified name of the business interface of this session bean. For example, if you specifymappedName="bank"
and the fully qualified name of the business interface iscom.CheckingAccount
, then the JNDI of the business interface isbank#com.CheckingAccount
.Code Example: