Controller @Mixin just works after recompile of running app

删除回忆录丶 提交于 2019-12-04 05:49:27

I had been regularly running into the same MissingMethodException when following a similar code reuse pattern using mixins.

In my case, changing groovy.lang.Mixin to grails.util.Mixin (or more specifically, adding an import for grails.util.Mixin to my controller) resolved the issue completely.

As for not having access to the controller variables, you may be stuck waiting for GRAILS-9905 to be resolved. I should note that there are some suggested work-arounds listed on the defect discussion, though.

The workaround that finally worked for me was to manually injecting the Mixin in the Controller constructor:

import com.example.MyMixin

class SomethingController {
  def SomethingController() {
    SomethingController.metaClass.mixin(MyMixin)
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!