【发布时间】:2014-07-14 19:46:48
【问题描述】:
我收到错误“由 NullPointerException 引起:null ->> 64 | grails.plugin.mail.MailService 中的 getMailConfig”。我已经按照邮件插件提供的文档配置了 config.groovy。
请帮我解决这个问题。
在下面找到我的 config.groovy 代码。
grails
{
mail {
host = "smtp.gmail.com"
port = 465
username = "xxxxxx@gmail.com"
password = "xxxxxx"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
在下面找到我的 groovy 类代码。
package common
import grails.plugin.mail.*;
public class FlowSchedule implements Job {
def mailService = new MailService()
public void execute(JobExecutionContext context)
throws JobExecutionException {
//some extra logic here
sendEmail(schedulerEntry.name,schedulerEntry.email)
}
def sendEmail(String name,String email)
{
mailService.sendMail {
to "amith.ravuru@citrix.com"
subject "Hello Amith"
body 'this is some text'
}
}
}
完整的错误跟踪:
Error |
2014-07-14 12:41:00,041 [DefaultQuartzScheduler_Worker-4] ERROR core.ErrorLogger - Job (group.Job_1 threw an exception.
Message: Job threw an unhandled exception.
Line | Method
->> 213 | run in org.quartz.core.JobRunShell
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
**^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by NullPointerException: null**
**->> 64 | getMailConfig in grails.plugin.mail.MailService**
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 59 | sendMail in ''
| 94 | sendEmail in common.FlowSchedule$$EOk1HyVA
| 79 | execute in ''
| 202 | run in org.quartz.core.JobRunShell
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
【问题讨论】:
-
你能在你的工作中打印
grailsApplication.config.grails.mail的值,看看它是否正确吗? -
不,grailsApplication 以 Null 形式出现。我通过将我的代码移动到一个新的控制器中并从 src/groovy 文件夹中存在的类中调用该函数来解决它。当我的 groovy 类出现在 src/groovy 文件夹中时,没有发生注入。
标签: grails plugins groovy sendmail