是否有任何有效的理由将石英作业宣布为弹簧豆?

发布于 2025-01-30 23:35:15 字数 1059 浏览 7 评论 0原文

通过查看一些在Spring Boot应用中运行石英作业的示例,我看到其中许多实际上是在用obion使用@component注释:

  • https://www.baeldung.com/spring-quartz-schedule#1-job“ rel = ” quartz-to-spring-boot“ rel =” nofollow noreferrer“> dzone 示例
  • 媒介示例

似乎完全没有用,因为每次触发作业时,工作工厂都会创建一个新实例。

我可以在我的应用中看到,方法 springbeanjobfactory.createjobinstance 每次执行作业时,都称为称为。我删除了@component注释,它运行完美,因此将作业宣布为弹簧bean有任何优势吗?

By looking at some examples of running quartz jobs in a spring boot app, I see many of them are actually declaring the Job with the @Component annotation :

It seems to be completly useless as the job factory will create a new instance every time the job is triggered.

I can see in my app that the method SpringBeanJobFactory.createJobInstance is called each time the job is executed. I removed the @Component annotation and it works perfectly, so is there any advantage of declaring a Job as a spring bean ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在某些情况下,您需要将弹簧托管组件注入您的工作,例如某些服务或存储库(以获取一些数据以通过工作处理)。在这种情况下,您想创建一个组件的作业,并允许弹簧向其注入所需的bean。在这种情况下,您的工作超类可以扩展Quartzjobbean。

In some cases you need to inject spring managed components into your job, for example some service or repository (to get some data to process by job). In such case, you wanna create a job as a component and allows spring to inject required beans into it. In such case your job's superclass can extend QuartzJobBean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文