run-app 和 run-war 之间的 Grails 行为差异
我对 Groovy 和 Grails 还比较陌生,我正在业余时间尝试它们。 我有一个小型测试 Grails 应用程序,可以使用 grails run-app 正常运行,但 grails run-war 会导致错误。
在 grails-app/conf/BootStrip.init
方法中,我将一些属性 getter 添加到 DefaultGrailsControllerClass
和 DefaultGrailsApplication
上:
DefaultGrailsControllerClass.metaClass.getMenuText = { ->
getPropertyOrStaticPropertyOrFieldValue('menuText', String.class)
}
DefaultGrailsControllerClass.metaClass.getMenuOrder = { ->
getPropertyOrStaticPropertyOrFieldValue('menuOrder', Integer.class)
}
DefaultGrailsApplication.metaClass.getMenuControllerClasses = { ->
controllerClasses.findAll { it.menuText != null }.sort { it.menuOrder }
}
在我的 < code>grails-app/views/layouts/main.gsp,我正在使用这个:
<g:each var="c" in="${ grailsApplication.menuControllerClasses }">
<li><g:link controller="${c.logicalPropertyName}">${c.menuText}</g:link></li>
</g:each>
这在 run-app
下工作正常,但在 run-war< 下运行它/code>,我得到以下信息:
groovy.lang.MissingPropertyException: No such property: menuControllerClasses for class: org.codehaus.groovy.grails.commons.DefaultGrailsApplication
我在 Grails 1.1.1 和 1.2-M1 下尝试过此操作并得到相同的结果。 我已经验证了 BootStrap.init
方法正在被调用(通过 println
),但是对 metaClass
所做的更改没有被调用似乎是在 run-war
下进行的。
知道我缺少什么吗?
I'm relatively new to Groovy and Grails and am trying them out in my spare time. I've got a small test Grails application that I'm able to run fine using grails run-app
, but grails run-war
results in an error.
In the grails-app/conf/BootStrip.init
method, I'm adding some property getters onto the DefaultGrailsControllerClass
and DefaultGrailsApplication
:
DefaultGrailsControllerClass.metaClass.getMenuText = { ->
getPropertyOrStaticPropertyOrFieldValue('menuText', String.class)
}
DefaultGrailsControllerClass.metaClass.getMenuOrder = { ->
getPropertyOrStaticPropertyOrFieldValue('menuOrder', Integer.class)
}
DefaultGrailsApplication.metaClass.getMenuControllerClasses = { ->
controllerClasses.findAll { it.menuText != null }.sort { it.menuOrder }
}
In my grails-app/views/layouts/main.gsp
, I'm using this:
<g:each var="c" in="${ grailsApplication.menuControllerClasses }">
<li><g:link controller="${c.logicalPropertyName}">${c.menuText}</g:link></li>
</g:each>
This works fine under run-app
, but running it under run-war
, I get the following:
groovy.lang.MissingPropertyException: No such property: menuControllerClasses for class: org.codehaus.groovy.grails.commons.DefaultGrailsApplication
I've tried this under Grails 1.1.1 and 1.2-M1 and get the same result. I've verified that the BootStrap.init
method is being called (via a println
), but the changes made to the metaClass
don't appear to take under run-war
.
Any idea what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
grails run-war -- 在 Jetty 中运行 Grails 应用程序的 WAR
grails run-app -- 在 Jetty 中运行 Grails 应用程序
区别似乎在于 run-war 不支持像 run-app 那样重新加载。
不知道你错过了什么。
grails run-war -- Run's a Grails application's WAR in Jetty
grails run-app -- Runs a Grails application in Jetty
The difference seems to be that run-war does not support reloading as run-app does.
Not sure what you are missing.