在静态方法中调用grailsApplication

时间:2015-04-08 20:42:19

标签: groovy

在我定义的班级中,

def grailsApplication;

现在在静态方法中我试图访问它并且它给出了一个错误:

Groovy:Apparent variable 'grailsApplication' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:

如何在静态方法中访问 grailsApplication

1 个答案:

答案 0 :(得分:2)

将其作为方法参数传递:

static someMethod( grailsApplication ){...}

Grails开发人员不鼓励使用静态技巧来访问app-context