Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 在静态方法内调用grailsApplication_Groovy - Fatal编程技术网

Groovy 在静态方法内调用grailsApplication

Groovy 在静态方法内调用grailsApplication,groovy,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?将其作

在我的课堂上,我定义了

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

将其作为方法参数传递:

static someMethod( grailsApplication ){...}

Grails开发人员不鼓励使用静态技巧访问应用程序上下文

“Grails开发人员不鼓励使用静态技巧访问应用程序上下文”-这个问题没有提到任何关于访问应用程序上下文的内容。有什么理由相信他/她正试图这么做吗?嗯,由于缺乏信息,我不得不运用我的想象力:)我明白了。人们与grailsApplication交互有很多原因,这些原因并不直接涉及应用程序上下文。