我有一个非常标准的2.0.3 Grails应用程序,我已经执行了grails install-templates在src/templates/scaffolding /目录中放置文件list.gsp,edit.gsp等.对它们进行更改时,不会自动重新加载这些文件.有没有办法让我自动重新加载这些,所以每次做出改变时我都不必停止/启动应用程序?我试过看看watchedResources,但这似乎与插件开发相关.
Ian*_*rts 11
你认为"观察资源"机制仅适用于插件是正确的.对此的正确修复是修改ScaffoldingGrailsPlugin.groovy要添加的核心
def watchedResources = "file:./src/templates/scaffolding/*"
Run Code Online (Sandbox Code Playgroud)
并且可能值得为此提交JIRA.与此同时,您可以通过编写自己的简单插件将此行为"注入"脚手架插件来使其工作.不要grails create-plugin watch-scaffolding再使用该插件描述如下:
import org.codehaus.groovy.grails.plugins.GrailsPlugin
class WatchScaffoldingGrailsPlugin {
def version = "0.1"
def grailsVersion = "2.0 > *"
def dependsOn = [:]
def pluginExcludes = [ "grails-app/views/error.gsp" ]
def title = "Watch Scaffolding Plugin"
def author = "Your name"
def authorEmail = ""
def description = '''\
Watches for changes to scaffolding templates and reloads dynamically-scaffolded
controllers and views.
'''
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/watch-scaffolding"
// watch for changes to scaffolding templates...
def watchedResources = "file:./src/templates/scaffolding/*"
// ... and kick the scaffolding plugin when they change
def onChange = { event ->
event.manager.getGrailsPlugin('scaffolding').notifyOfEvent(
GrailsPlugin.EVENT_ON_CHANGE, null)
}
// rest of plugin options are no-op
def onConfigChange = { event -> }
def doWithWebDescriptor = { xml -> }
def doWithSpring = { }
def doWithDynamicMethods = { ctx -> }
def doWithApplicationContext = { applicationContext -> }
def onShutdown = { event -> }
}
Run Code Online (Sandbox Code Playgroud)
现在在您的应用程序中BuildConfig.groovy添加
grails.plugin.location.'watch-scaffolding' = '../watch-scaffolding'
Run Code Online (Sandbox Code Playgroud)
(或者从应用程序根目录到插件根目录的任何适当的相对路径),脚手架模板更改应该开始自动重新加载.
(这是在Grails 2.1上测试的,我最初尝试使用影响但它没有任何影响,但是强制onChange脚手架插件中的事件具有所需的结果.)
| 归档时间: |
|
| 查看次数: |
2221 次 |
| 最近记录: |