使用Quartz Scheduler的Java Web应用程序中的电子邮件通知和提醒 [英] Email Notifications and Reminders in Java Web app using Quartz Scheduler

查看:318
本文介绍了使用Quartz Scheduler的Java Web应用程序中的电子邮件通知和提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个简单的Java Web应用程序,在一些任务完成后发送电子邮件通知,例如提交批准的请求,以及定期的提醒(说出批准者)。我想使用Quartz Scheduler来执行此操作。我是一个新手,任何人都可以帮助我开始这个。

I want to develop a simple Java Web app to send an email notifications after some task is done, such as a request submitted for approval, and reminders (to say approvers) at regular intervals. I want to do this using the Quartz Scheduler. I am a newbie, so can anyone help me to start on this.

感谢提前。

我复制并粘贴JAR文件:在WEB-INF \lib中的quartz-1.8.0,甚至在common \lib中,然后在我的Java文件中导入时找不到。 (

I copy and pasted the JAR file : quartz-1.8.0 in WEB-INF\lib and even in common\lib, then it is not found while importing in my Java file. :(

推荐答案

创建一个从web应用程序初始化开始的servlet。

Create a servlet that starts at web-app init.

<web-app>
    ...
    <servlet>
     <servlet-name>Emailer</servlet-name>
     <servlet-class>my.servlet.Emailer</servlet-class>
     <load-on-startup>1</load-on-startup>
    </servlet>
    ...
</web-app>

code> init()配置您的调度程序(下面的示例每10分钟触发一次)

In init() of the servlet configure your scheduler (the example below triggers every 10 minutes)

SchedulerFactory schFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schFact.getScheduler();
JobDetail job = new JobDetail("job1", "group1", EmailerJob.class);
CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "group1", "* 0/10 * * * ?");
sched.addJob(job, true);
sched.start();

nt工作界面的Quartz。

Write a Class inplementing Job interface of Quartz.

EmailerJob implement Job{
        public void execute(JobExecutionContext arg0) throws JobExecutionException {
        //Code to send mails goes here
    }

}

PS 上面的代码没有被测试,但它给你一个公平的想法该怎么做。

P.S. The code above is not-tested, but it gives you a fair idea what to do.

As @ jmort253 rightly Quartz的教程是最好的资源,如果我记得正确的话,他们有一个预定的emailer示例。

As @jmort253 rightly pointed, Quartz tutorial is the best resource and if I remember correctly, they have an scheduled emailer example done somewhere in that.

更新

好的,Google解决你的问题。这是您最详细的解决方案,任何人都可以给你! Java - 使用石英API的Web应用程序中的作业调度

Alright, Google to solve your issue. And here is your most detailed solution that anyone can give to you! Java – Job Scheduling in web application with quartz API

编辑#1 您可以使用 ContextListener 而不是servlet来启动Quartz调度器。

Edit#1 You may use ContextListener instead of servlet to initiate Quartz scheduler.

更新1

Job ,可以问Quartz预定义的 SendMailJob 类做同样的事情。感谢@jhouse。

As @jhouse rightly mentioned that instead of writing your own Job that handle mailing, you can ask Quartz predefined SendMailJob class to do the same. Thanks @jhouse.

这篇关于使用Quartz Scheduler的Java Web应用程序中的电子邮件通知和提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆