是否有任何有效的理由将石英作业宣布为弹簧豆?
通过查看一些在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.