Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
使用Grails远程控制访问静态常量_Grails_Groovy - Fatal编程技术网

使用Grails远程控制访问静态常量

使用Grails远程控制访问静态常量,grails,groovy,Grails,Groovy,如果我有类似的东西,在测试中使用Grails远程控制 class FooTest { static final String CONSTANT = "some constant" def remote = new Remote() def testUsingRemote() { remote { new DomainObject(name: FooTest.CONSTANT).save() } } } 在远程端执行时,闭包可能会因

如果我有类似的东西,在测试中使用Grails远程控制

class FooTest {
   static final String CONSTANT = "some constant"
   def remote = new Remote()

   def testUsingRemote() { 
     remote { 
       new DomainObject(name: FooTest.CONSTANT).save()
     }
   }
}
在远程端执行时,闭包可能会因NoClassDefFoundError而中断,因为FooTest类本身不在部署的应用程序中

我可以通过将常量赋给局部变量,然后在闭包中使用局部变量(通过词法作用域提供局部变量)来修复它:

全面解决这个问题的好方法是什么

理想情况下:在序列化闭包之前,有没有办法解析或内联常量

 def constant = FooTest.CONSTANT
 remote {
   new DomainObject(name: constant).save()
 }