使用Grails远程控制访问静态常量
如果我有类似的东西,在测试中使用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() } } } 在远程端执行时,闭包可能会因
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()
}