5

升级到 Grails 2.3.5 后,我发现我的 mixin 仅在 JVM 分叉关闭时才有效。

我所有的控制器都有这样的代码

import util.MyMixin

@Mixin(MyMixin)
class MyController {

在哪里MyMixin定义src/groovy/util并且看起来像

package util

class MyMixin {
    private def aMethod(someArgs) {
        // do something
    }
}

BuildConfig.groovy包含以下代码时

forkConfig = [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 256]
grails.project.fork = [
   test: forkConfig, // configure settings for the test-app JVM
   run: forkConfig, // configure settings for the run-app JVM
   war: forkConfig, // configure settings for the run-war JVM
   console: forkConfig // configure settings for the Swing console JVM
]

然后我收到以下错误

MissingMethodException occurred when processing request:
No signature of method: MyController.aMethod() is applicable for argument types

参数类型匹配的地方,当然,当我没有 JVM 分叉代码时,代码可以工作BuildConfig.groovy

在分叉 JVM 时,我需要做一些特别的事情来让 mixin 工作吗?我只使用分叉是因为 Grails 2.3.5 推荐它,但我在不使用它时遇到了问题:Grails 2.3.5 在每次代码更改后都需要“grails clean”

4

1 回答 1

0

我在将 Mixins 与 Grails 域对象一起使用时遇到了困难,听到您在使用 Controller 时遇到了困难,我并不感到惊讶。域、控制器和服务由 Grails 管理得如此繁重,难怪普通的 @Mixins 可能会以某种方式被破坏。我已经成功地通过 metaClass builder DSL 专门注入方法,如下所示:

targetClass.metaClass {
    someMethod { someParam ->
        // do something
    }
}

您必须自己在所有目标类上调用它......它不像@Mixin 那样优雅,但它似乎有效。

于 2014-05-31T03:07:12.770 回答