Grails 1.3.7에서 Grails 2.2로 포팅하려고하는 코드가 있습니다.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() {
}
}
파생 클래스의 예는이 Grails를 1.3.7에서 일
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를 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 : 그에게 할 수있는 사람 : - 입력 된 필드 (GrailsApplication
)이 있으므로 def
필드에 초를 생성으로 필드가 이미 AST 변환을 통해 클래스의 바이트 코드에 추가됩니다