我通过执行以下操作将我的 Grails 1.3.7 应用程序升级到 Grails 2.2

  • 设置GRAILS_HOME Grails 2.2
  • 位置的变量
  • 编辑了指向此位置的路径
  • grails upgrade
  • 已编辑 application.properties删除所有插件引用
  • 已编辑 Build.config创建 plugins关闭引用我的插件
  • grails clean
  • grails compile

  • 步骤 7 失败并出现以下错误:
    C:\code\querium\AppServer-grails-2>grails compile --stacktrace 
    | Compiling 98 source files 
    | Warning The [executeSafely] action accepts a parameter of type [groovy.lang.Closure] which has not been marked with @V 
    alidateable.  Data binding will still be applied to this command object but the instance will not be validateable. 
     
           def executeSafely(Closure c) { 
           ^ 
    | Warning The [executeSafely] action accepts a parameter of type [groovy.lang.Closure] which has not been marked with @V 
    alidateable.  Data binding will still be applied to this command object but the instance will not be validateable. 
     
            def executeSafely(Closure c) { 
        ^ 
    | Warning The [increment] action accepts a parameter of type [java.util.Map] which has not been marked with @Validateabl 
    e.  Data binding will still be applied to this command object but the instance will not be validateable. 
     
            def increment(Map map, String t, int index) { 
        ^ 
    | Compiling 98 source files. 
    | Error Fatal error during compilation org.apache.tools.ant.BuildException: Compilation Failed (NOTE: Stack trace has be 
    en filtered. Use --verbose to see entire trace.) 
    java.lang.NullPointerException 
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
            at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
            at org.codehaus.gant.GantBuilder.invokeMethod(GantBuilder.java:99) 
            at _GrailsCompile_groovy$_run_closure2_closure6_closure7.doCall(_GrailsCompile_groovy:48) 
            at _GrailsCompile_groovy$_run_closure2_closure6_closure7.doCall(_GrailsCompile_groovy) 
            at _GrailsCompile_groovy.withCompilationErrorHandling(_GrailsCompile_groovy:69) 
            at _GrailsCompile_groovy.this$4$withCompilationErrorHandling(_GrailsCompile_groovy) 
            at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) 
            at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:168) 
            at _GrailsCompile_groovy$_run_closure2_closure6.doCall(_GrailsCompile_groovy:47) 
            at _GrailsCompile_groovy$_run_closure2_closure6.doCall(_GrailsCompile_groovy) 
            at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) 
            at _GrailsCompile_groovy$_run_closure2.doCall(_GrailsCompile_groovy:46) 
            at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) 
            at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) 
            at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:1 
    85) 
            at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy) 
            at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90) 
            at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy) 
            at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185) 
            at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy) 
            at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) 
            at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) 
            at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) 
            at gant.Gant.withBuildListeners(Gant.groovy:427) 
            at gant.Gant.this$2$withBuildListeners(Gant.groovy) 
            at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) 
            at gant.Gant.dispatch(Gant.groovy:415) 
            at gant.Gant.this$2$dispatch(Gant.groovy) 
            at gant.Gant.invokeMethod(Gant.groovy) 
            at gant.Gant.executeTargets(Gant.groovy:591) 
            at gant.Gant.executeTargets(Gant.groovy:590) 
    | Error Fatal error during compilation org.apache.tools.ant.BuildException: Compilation Failed 
    

    我不确定真正的错误在哪里,以及如何纠正它。我很乐意忽略这些警告,除非有充分的理由来修复它们。 (如果有,怎么做?)

    请您参考如下方法:

    我不确定 NPE,但警告是由于 Controller 中的公共(public)方法引起的。 Controller 不能从应用程序代码中调用,所以公共(public)方法没有意义。在 2.0+ 中, Action 现在可以是除了闭包之外的方法,因此您的辅助方法被误解为 Controller Action 。将它们设为私有(private),警告就会消失,幸运的是,NPE 也会消失。

    顺便说一句,文档中有升级信息:)


    评论关闭
    IT序号网

    微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!