使用grails插件数据源 [英] Use grails plugin datasource

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

问题描述

我正在使用Grails 2.2.4构建一个插件。该插件是一个访问管理器,需要访问一些数据源(不止一个)。当Grails手册在提供基本文物中指定时, DataSource.groovy 未与插件捆绑在一起。

I'm using Grails 2.2.4 to build a plugin. The plugin is an access manager and need to access some datasources (more than one). As the Grails manual specify in Providing Basic Artefacts, the DataSource.groovy is not bundled with the plugin.

有没有办法复制将DataSource.groovy文件插入到使用该插件的应用程序的DataSource.groovy文件中?

Is there a way to "copy" the datasources defined on the plugin DataSource.groovy file to the application's DataSource.groovy file that uses the plugin?

我真的不想在每个使用插件的应用程序上手动定义插件数据源插件。

I really don't want to manually define the plugin datasources on every application that uses the plugin.

============

============

完整的堆栈追踪)

2013-12-11 11:39:33,055 ERROR org.codehaus.groovy.grails.web.context.GrailsConte
xtLoader - Error initializing the application: groovy.lang.MissingMethodExceptio
n: No signature of method: portal.Aplicacao.methodMissing() is applicable for ar
gument types: () values: []
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMetho
dException: No signature of method: portal.Aplicacao.methodMissing() is applicab
le for argument types: () values: []
        at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.
java:308)
        at grails.util.Environment.executeForEnvironment(Environment.java:301)
        at grails.util.Environment.executeForCurrentEnvironment(Environment.java
:277)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor     .java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: groovy.lang.MissingMethodException: No signature of method: portal.Ap
licacao.methodMissing() is applicable for argument types: () values: []
        at portal.PortalService.criaAplicacaoNoPortal(PortalService.groovy:233)
        at BootStrap$_closure1.doCall(BootStrap.groovy:16)
        ... 8 more


推荐答案

您可以使用平台核心插件,然后定义dataSources作为应用程序配置插件的 doWithConfig 部分,如下所示:

You can use the platform-core plugin, and then define the dataSources as application config in the doWithConfig section of your plugin, like so:

def doWithConfig = { config ->

    // ...

    application {
        Environment.executeForCurrentEnvironment {
            development {
                    dataSource_myDatasource {
                        dbCreate = "create-drop"
                        url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
                        // other datasource configuration here...
                    }
                }
            }
            test {
                    dataSource_myDatasource {
                        // test datasource
                        dbCreate = "create-drop"
                        url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
                        // ...
                    }
                }
            }
        }
    }
}

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

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