I have a Service, called Mailer
, and a controller, which should use this service:
class DocumentController {
def mailer
def publish = {
mailer.sendReport()
}
}
But when I call publish
I get:
java.lang.NullPointerException: Cannot invoke method sendReport() on null object
Why doesn't the dependency injection work here?
Grails is all about conventions. I think mailer needs to be called mailerService. It needs to be in the services directory. Controller needs to be in the controllers directory.
From the documentation
"A service contains business logic that can be re-used across a Grails application. In Grails a service is a class that ends in the convention "Service" and lives in the grails-app/services directory. A service can be created with the create-service command:"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With