Running Grails dependencies through autoload does not work

I have a Service called Mailer, and a controller that 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 is dependency injection not working here?

+3
source share
1 answer

Grails is all about conventions. I think the mailer should be called mailerService. It must be in the services directory. The controller must be in the controller directory.

From the documentation

" -, Grails. Grails - , " " grails-app/services. create-service:"

+6

Source: https://habr.com/ru/post/1786763/


All Articles