安装mongeez插件时出错

时间:2016-07-12 19:14:03

标签: mongodb grails

我正在尝试安装mongeez插件,我收到以下错误, 我已经包括了, 插件{ ..  编译':mongeez:0.2.3' .. } 在BuildConfig.groovy中

创建名为'grails.mongeez.MongeezController'的bean时出错:bean的初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'mongeez'的bean时出错:在设置bean属性'mongo'时无法解析对bean'mongo'的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为'mongo'的bean ..... ..... .... .... ..... .....

引起:org.springframework.beans.factory.BeanCreationException:创建名为'mongeez'的bean时出错:设置bean属性'mongo'时无法解析对bean'mongo'的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为'mongo'的bean

2 个答案:

答案 0 :(得分:0)

I'm able to install the plugin by adding mongeez as a dependency instead of a plugin.

BuildConfig.groovy

 dependencies {
......
.....
compile 'org.mongeez:mongeez:0.9.6'
.....
......
}

Contents of  migrations folder(Change logs)
I have grails-app/migrations/test.js 
       grails-app/migrations/mongeez.xml

This is my mongeez.xml

<changeFiles>
    <file path="test.js"/>
</changeFiles>

This is my test.js

db.movie.insert({
    "name":"tutorials point"
});


I have written a groovy script as follows,


import com.mongodb.Mongo
import org.springframework.core.io.ClassPathResource
import org.mongeez.Mongeez

includeTargets << grailsScript("_GrailsInit")

target(updateMongo: "Update the mongo DB!") {
    println "The script is about to run"

    def host = 'localhost'
    def port = 27017
    def databaseName = 'reporting'

    Mongeez mongeez = new Mongeez()
    mongeez.setFile(new ClassPathResource("/migrations/mongeez.xml"))
    mongeez.setMongo(new Mongo(host, port))
    mongeez.setDbName(databaseName)
    mongeez.process()

    println "The script just ran"
}
setDefaultTarget(updateMongo)




When I run the above script both the print statements are getting executed.
A mongeez collection also got created in my reporting db but the contents of test.js(movie collection) is not reflected in my mongodb , i.e movie collection is not getting created.

Please suggest me if I'm missing something. 

答案 1 :(得分:0)

Got mongeez plugin working by replacing ClassPathResource with FileSystemResource.

Mongeez mongeez = new Mongeez()
 mongeez.setFile(new FileSystemResource(path)) // Give the path to your mongeez.xml
 mongeez.setMongo(new Mongo(properties.host, properties.port))
 mongeez.setDbName(databaseName)
 mongeez.process()