将 Spring AOP 与 Quartz 调度程序结合使用
我在我的项目中使用 Quartz 调度程序来进行调度。我需要收集统计数据,例如作业运行的时间、持续时间和次数。我想使用 Spring AOP 来实现同样的目的。为此,我正在制作 Job 类 spring 管理的 bean。 Spring 为每个 Job 类创建一个 Proxy 类。但是现在,当 Quartz 尝试执行这个 spring 管理的作业时,我收到了 Spring 为该作业创建的 Proxy 类的 InstantiationException 异常。
org.quartz.SchedulerException:实例化类“$Proxy6”时出现问题 [请参阅嵌套异常:java.lang.InstantiationException:$Proxy6]
任何人都可以建议解决此问题的方法吗?
I am using Quartz scheduler for scheduling purposes in my project. I need to gather statistics like when, for how long, and how many times a job was run. I want to use Spring AOP for the same. For this, I am making Job classes spring-managed beans. Spring creates a Proxy class for each of the Job classes. But now when Quartz tries to execute this spring-managed Job, I am getting InstantiationException for the Proxy class created for the Job by Spring.
org.quartz.SchedulerException: Problem instantiating class '$Proxy6'
[See nested exception: java.lang.InstantiationException: $Proxy6]
Can anybody please suggest a solution for this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
因为Quartz Job类是由Quartz容器而不是Spring容器管理的,所以Spring AOP无法实现你的目标。出于您的目的,有两种方法可以实现此目的:
Quartz 具有内置侦听器机制,您可以使用全局侦听器来完成您想要的操作,就像 AOP 一样。关于监听器的更多信息,请参考:Quartz文档< /a>.
如果你坚持Spring AOP,你就必须自定义作业类实例化过程,让作业类由Spring容器来管理。一种方法是编写自己的 JobFactory,它扩展
SpringBeanJobFactory
然后重写createJobInstance()
方法。如果你想了解更多这方面的内容,请评论这个,我会写更多细节。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如果你直接使用quarz(不通过Spring Schedule注释),你可以直接向quarz询问统计数据。 -- 其中许多已经在 quarz 中实现了。
If you use quarz directly (not via Spring Schedule annotation), you can ask quarz directly for the statistics. -- Many of them are already implemented in quarz.