私はかなり標準的な2.0.3Grailsアプリを持っており、grails install-templates
ファイルlist.gsp、edit.gspなどをsrc /テンプレート/scaffolding/ディレクトリに配置する実行を実行しました。これらのファイルは、変更が加えられても自動的に再ロードされません。これらを自動的にリロードして、変更を加えるたびにアプリを停止/開始する必要がないようにする方法はありますか?watchedResourcesを見てみましたが、プラグイン開発に関連しているようです。
3 に答える
「watched-resources」メカニズムがプラグインにのみ適用されることは正しいです。これに対する正しい修正は、コアScaffoldingGrailsPlugin.groovy
を変更して追加することです。
def watchedResources = "file:./src/templates/scaffolding/*"
おそらく、その趣旨で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 -> }
}
アプリケーションのBuildConfig.groovy
追加で
grails.plugin.location.'watch-scaffolding' = '../watch-scaffolding'
(または、アプリのルートからプラグインのルートへの適切な相対パス) と、スキャフォールディング テンプレートの変更が自動的に再読み込みを開始するはずです。
(これは Grails 2.1 でテストされています。最初にインフルエンスを使用してみましたが、効果はありませんでしonChange
たが、scaffolding プラグインでイベントを強制すると、必要な結果が得られました。)
このコードは、スキャフォールディング キャッシュをフラッシュします。特定の管理アクションを作成できます。
org.codehaus.groovy.grails.scaffolding.view.
ScaffoldingViewResolver.scaffoldedViews.clear()
GRAILS-755によると、これは修正されていますが、リロードもしないため、修正されていないと思います。
その Jira から、考えられる回避策を次に示します。
コンソール プラグインを使用し、次のコマンドを実行して、動的なスキャフォールディング ビュー キャッシュをクリアします。
def scaffoldedView = org.codehaus.groovy.grails.scaffolding.view.ScaffoldingViewResolver.scaffoldedViews.clear()</p>
その後、次にページを要求すると、キャッシュ内にそのページが見つからないため、ディスクに戻って再作成します。