I use a Grails Job to start a Service which uses g.formatDate
. When using the service directly from a Controller I have no problem. When I use the Service from the Job I get the following error:
ERROR listeners.ExceptionPrinterJobListener - Exception occurred in job: Grails Job
Message: java.lang.NullPointerException
Line | Method
->> 111 | execute in grails.plugins.quartz.GrailsJobFactory$GrailsJob
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 202 | run in org.quartz.core.JobRunShell
^ 573 | run . . in org.quartz.simpl.SimpleThreadPool$WorkerThread
Caused by NullPointerException: null
->> 245 | $tt__sendReportCompanyWeekly in Test.SendMailService$$EPPc274K
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 47 | doCall in Test.ReportCompanyWeeklyJob$_execute_closure1
| 31 | execute in Test.ReportCompanyWeeklyJob$$EPPc2HTU
| 104 | execute in grails.plugins.quartz.GrailsJobFactory$GrailsJob
| 202 | run . . in org.quartz.core.JobRunShell
^ 573 | run in org.quartz.simpl.SimpleThreadPool$WorkerThread
Here is my Job:
class ReportCompanyWeeklyJob {
SendMailService sendMailService
static triggers = {
cron name: 'scheduledReportCompanyWeeklyJob', cronExpression: "0 15 22 ? * *"
}
def execute() {
sendMailService.sendReportCompanyWeekly(company.id, user.id)
}
}
Here is my Service:
@Transactional
class SendMailService {
def gspTagLibraryLookup // being automatically injected by spring
def g
def sendReportCompanyWeekly(String companyId, String userId) {
g = gspTagLibraryLookup.lookupNamespaceDispatcher("g")
Date today = new Date()
Locale locale = // some locale
// Line 245
def test = g.formatDate(date: today, formatName: 'date.format.long.no.year', locale: locale)
}
}
Edit: I use groovyPageRenderer.render(template: viewPathHTML, model: myModel)
to render a GSP in a service.
How can I make g.formatDate
work when running from a Job?