开发者

Grails dependency injection via autowiring doesn't work

开发者 https://www.devze.com 2023-02-06 08:14 出处:网络
I have a Service, called Mailer, and a controller, which should use this service: class DocumentController {

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开发者_如何学C 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:"

0

精彩评论

暂无评论...
验证码 换一张
取 消