禁用Grails插件 [英] Disable Grails plugin

查看:61
本文介绍了禁用Grails插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Grails应用中,我想防止在运行单元测试时加载Searchable插件.我尝试在Bootstrap类中使用以下代码来做到这一点

In my Grails app, I want to prevent the Searchable plugin from loading when running my unit tests. I tried doing this using the following code in the Bootstrap class

def grailsApplication

def init = {servletContext ->
    def currentEnv = grails.util.Environment.current.name

    if (currentEnv == 'test') {

        def doNothing = {println "Searchable is disabled"}

        // This returns null!
        def searchablePluginClass = grailsApplication.getClassForName("SearchableGrailsPlugin")

        searchablePluginClass.metaClass.doWithDynamicMethods = doNothing 
        searchablePluginClass.metaClass.doWithSpring = doNothing 
        searchablePluginClass.metaClass.doWithApplicationContext = doNothing 
    }
}

但是,这是行不通的,因为grailsApplication.getClassForName("SearchableGrailsPlugin")返回null,大概是因为运行此代码时此类不在类路径上.还有其他方法可以禁用此插件吗?

However this doesn't work because grailsApplication.getClassForName("SearchableGrailsPlugin") returns null, presumably because this class isn't on the classpath when this code runs. Is there any other way that I can disable this plugin?

推荐答案

我找到了解决方案.将以下内容添加到Config.groovy:

I found a solution. Add the following to Config.groovy:

environments {
    test {
        plugin {
            excludes = "searchable"
        }
    }
}

这篇关于禁用Grails插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆