在带有 Spring 的 Web 应用程序中使用 Quartz
我创建了一个小型控制台应用程序来查看quartz 的工作原理,并且很容易在 main 方法中创建一个 applicationcontext 对象来运行 cron。好的,现在我处于一个由 Maven 管理的真实项目中,该项目使用某些模块中定义的 cron 作业。每个模块都有自己的 spring 配置文件。我有 3 个使用石英的模块,因此它是在每个 spring 配置文件中设置的。 Web 应用程序模块是具有每个模块的依赖性的模块。
现在我几乎没有什么顾虑:
我应该像在控制台项目中一样创建
applicationcontext
还是应该加载它。如果是,我应该在哪里加载它。根据我在网上所做的研究,我使用
MethodInvokingJobDetailFactoryBean
来轻松进行单元测试。现在我必须使用CronExpression
类来测试getNextValidTimeAfter
,
任何人都可以帮助我。我真的很感激。感谢您的阅读
I've created a small console application to see how quartz work and it was easy to create an applicationcontext
object inside the main method to get the cron run. OK now I'm in a real project managed by maven and which is using cron jobs defined in some of the modules. Each of the module has his own spring config file. I had 3 of the modules using quartz so it was setup in each of the spring config file. The web app module is the one who has the dependency of each of the modules.
Now i had few concerns:
should I created the
applicationcontext
as in the console project or it's supposed to be loaded. If yes, where am I supposed to load it.based on research on the Internet I did on line I use
MethodInvokingJobDetailFactoryBean
for easy unit testing. And now that I have to use theCronExpression
class to test thegetNextValidTimeAfter
, I still don't know how to organize it properly
Can anyone give me a hand. I'd really appreciate it. Thanks for reading
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据评论,问题更接近于“如何为 Web 应用程序加载 Spring 应用程序上下文文件”。
根据 第 3.8.5 节,“方便的 ApplicationContext Web 应用程序的实例化”,您可以使用
ContextLoaderListener
注册一个ApplicationContext
,如下所示(将其添加到您的web.xml
文件中) ):As per comment, the question is closer to "How to load Spring application context file(s) for a Web application".
According to Section 3.8.5, "Convenient ApplicationContext instantiation for web applications", you can register an
ApplicationContext
using theContextLoaderListener
as follows (add this to yourweb.xml
file):