开发者

Grails dependency injection via autowiring doesn't work

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜