升级到Grails 2.3.5后,我发现我的mixins仅在JVM forking关闭时才有效.
我的所有控制器都有这样的代码
import util.MyMixin
@Mixin(MyMixin)
class MyController {
Run Code Online (Sandbox Code Playgroud)
在哪里MyMixin定义src/groovy/util和看起来像
package util
class MyMixin {
private def aMethod(someArgs) {
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
当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
]
Run Code Online (Sandbox Code Playgroud)
然后我收到以下错误
MissingMethodException occurred when processing request:
No signature of method: MyController.aMethod() is applicable for argument types
Run Code Online (Sandbox Code Playgroud)
参数类型匹配的地方,当然,当我没有JVM分叉代码时代码可以工作BuildConfig.groovy.
在分叉JVM时,我需要做些什么才能让mixin工作?我只使用分叉,因为Grails 2.3.5推荐它并且当我不使用它时我遇到了问题:Grails 2.3.5在每次代码更改后都需要"grails clean"
我在使用 Mixins 和 Grails 域对象方面遇到了困难,并且当听到您在 Controller 方面遇到困难时我并不感到惊讶。域、控制器和服务都由 Grails 严格管理,难怪普通的 @Mixin 可能会以某种方式被破坏。我已经成功地通过元类构建器 DSL 专门注入方法,如下所示:
targetClass.metaClass {
someMethod { someParam ->
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
你必须在所有目标类上自己调用它......它不像@Mixin那么优雅,但它似乎有效。
| 归档时间: |
|
| 查看次数: |
143 次 |
| 最近记录: |