我有一些代码要从Grails 1.3.7移植到Grails 2.2。
当前的问题是,我有一个BaseController类,它定义了一些方便的方法,以及从它继承的特定控制器(实际上是由Grails实例化的)。
package com.fxpal.querium
import grails.converters.JSON
import groovy.lang.Closure;
abstract class BaseController {
protected def executeSafely(Closure c) {
def resp = null
try {
populateContext();
resp = c()
}
catch(Exception ex) {
resp = [error: ex.message]
ex.printStackTrace()
}
def json = resp as JSON
return json
}
protected void populateContext() {
}
}派生类的一个示例是
package com.fxpal.querium
import grails.converters.JSON
import grails.plugins.springsecurity.Secured
import javax.servlet.http.HttpServletResponse
@Secured(['IS_AUTHENTICATED_REMEMBERED'])
class DocumentController extends BaseController {
def grailsApplication
@Secured(['IS_AUTHENTICATED_ANONYMOUSLY'])
def getText = {
try {
String text = new URL(grailsApplication.config.querium.docurl + params.paperId).text
render contentType: 'text/plain', text: text
}
catch(Exception ex) {
render contentType: 'text/plain', text: "Error loading document: ${ex.getMessage()}; please retry"
}
}
...
}这在Grails 1.3.7中起作用。当我尝试用Grails 2.2编译我的应用程序时,我得到了以下错误:
C:\code\querium\AppServer-grails-2\grails-app\controllers\com\fxpal\querium\DocumentController.groovy: -1: The return ty
pe of java.lang.Object getGrailsApplication() in com.fxpal.querium.DocumentController is incompatible with org.codehaus.
groovy.grails.commons.GrailsApplication getGrailsApplication() in com.fxpal.querium.BaseController
. At [-1:-1] @ line -1, column -1.此模式不再受支持吗?我尝试将abstract添加到BaseController声明中(在Grails 1.3.7中这不是必需的),但这似乎没有任何区别。我是在清理之后编译代码的,如果这很重要的话。
PS:致那些有能力的人:请创建一个grails-2.2标签
发布于 2012-12-25 19:22:45
删除def grailsApplication -该字段已经作为类型化字段(GrailsApplication)通过AST转换添加到类字节码中,因此您的def字段将创建另一个具有较弱类型(Object)的get/set对。
https://stackoverflow.com/questions/14028149
复制相似问题