我正在使用 Grails 3.0.12,我正在使用 Quartz 执行一项工作,我现在尝试做的是每次发送一封电子邮件(在这种情况下每 5 秒)。我的服务文件夹中有电子邮件服务。这是我的代码:
class EnviaCorreosJob{
NotifierService notificar
Integer diasParaCorreo = 30
static triggers =
{
cron name: 'myTrigger', cronExpression: "*/5 * * * * ?"
}
def group = "MyGroup"
def description = "Example job with Cron Trigger"
def fechaHoy = new Date()
def execute()
{
println "------------------ Running every 5 seconds -------------------"
def queryAgenda = Agenda.where
{
inicio_cita <= (fechaHoy + diasParaCorreo)
}
def listaAgenda = queryAgenda.list()
println "----------------------Dates list : " + listaAgenda
log.info "listaAgenda: " + listaAgenda
log.info "listaAgendaTamaño: " + listaAgenda.size()
listaAgenda.each
{
agenda ->
println "it's inside"
mailService.sendMail
{
to "xxxxxx@gmail.com"
subject "hello"
body "hello"
}
}
}
}
我试图创建一个 Service 类的实例来调用 mailService.sendMail 但没有奏效。
非常感谢你的帮助。 :)
最佳答案
看起来您正在尝试在工作中使用邮件插件,但您尚未将邮件服务注入(inject)到您的工作中。
添加:
def mailService
到您的类(class),它将被注入(inject)并可用。更多关于服务注入(inject)的信息可以在这里找到 https://grails.github.io/grails-doc/latest/guide/single.html#dependencyInjectionServices
更多关于配置和使用邮件插件的信息在这里 - https://grails.org/plugins.html#plugin/mail
关于hibernate - Grails、ORM、 quartz 、乔布斯、,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36651292/