Use grails plugin datasource

Deadly 提交于 2019-12-11 00:14:07

问题


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.

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.

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

Full stacktrace (requested in comments)

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

回答1:


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"
                        // ...
                    }
                }
            }
        }
    }
}


来源:https://stackoverflow.com/questions/20501945/use-grails-plugin-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!