问题 使用Grails重新加载引导程序


在没有重新启动应用程序的情况下更改后,Grails中是否有一种方法可以运行BootStrap.groovy的内容?


2696
2018-05-03 21:05


起源



答案:


你可以这样做 console 插入。我强烈推荐这个插件用于任何开发环境,因为它对于在正在运行的服务器中运行ad-hoc代码非常有用。

重新运行BootStrap init 关闭,浏览到基于Web的控制台 http://localhost:8080/appname/console。在控制台中输入以下内容:

def servletCtx = org.codehaus.groovy.grails.web.context.ServletContextHolder.servletContext
def myBootstrapArtefact = grailsApplication.getArtefacts('Bootstrap')[-1]
myBootstrapArtefact.referenceInstance.init(servletCtx)

15
2018-05-03 22:48



如果你在init闭包中定义了环境,你怎么能运行它? - Johnnie


答案:


你可以这样做 console 插入。我强烈推荐这个插件用于任何开发环境,因为它对于在正在运行的服务器中运行ad-hoc代码非常有用。

重新运行BootStrap init 关闭,浏览到基于Web的控制台 http://localhost:8080/appname/console。在控制台中输入以下内容:

def servletCtx = org.codehaus.groovy.grails.web.context.ServletContextHolder.servletContext
def myBootstrapArtefact = grailsApplication.getArtefacts('Bootstrap')[-1]
myBootstrapArtefact.referenceInstance.init(servletCtx)

15
2018-05-03 22:48



如果你在init闭包中定义了环境,你怎么能运行它? - Johnnie