0

我正在从头开始创建应用程序,当我启动应用程序时,出现以下错误。我的 MongoDB 版本是 2.6.1

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: source can not be null
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 44 common frames omitted
Caused by: java.lang.IllegalArgumentException: source can not be null
    at com.mongodb.assertions.Assertions.notNull(Assertions.java:37) ~[mongodb-driver-core-3.2.1.jar:na]
    at com.mongodb.MongoCredential.<init>(MongoCredential.java:233) ~[mongodb-driver-core-3.2.1.jar:na]
    at com.mongodb.MongoCredential.createCredential(MongoCredential.java:106) ~[mongodb-driver-core-3.2.1.jar:na]
    at org.grails.datastore.gorm.mongo.bean.factory.MongoClientFactoryBean.afterPropertiesSet(MongoClientFactoryBean.java:145) ~[grails-datastore-gorm-mongodb-5.0.1.RELEASE.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]

我的数据源配置如下

grails {
            mongodb {
                host = "localhost"
                port = 27017
                username = "admin"
                password = "password"
                databaseName = "sta"
            }
        }
4

3 回答 3

0

我认为 GORM 插件中存在错误。它似乎无法识别 databaseName 属性。如果您使用连接字符串,它似乎确实有效。

connectionString: "mongodb://username:password@host:port/databaseName"

详情: https ://docs.mongodb.com/manual/reference/connection-string/

于 2017-01-03T23:48:30.300 回答
0

查看官方指南

如果你想配置 Grails 如何连接到 MongoDB,那么你可以使用 grails-app/conf/application.yml 中的以下设置来完成:

grails:
    mongodb:
        host: "localhost"
        port: 27017
        username: "blah"
        password: "blah"
        databaseName: "foo"

还要检查下一章:2.3 高级配置

于 2016-03-07T21:22:47.487 回答
0

我尝试了 .yml 文件和 .groovy 文件。我还创建了一个新示例,但它没有用。问题在于版本 3.1.1 附带的插件。一旦我升级到 3.1.3,问题就消失了。

于 2016-03-08T18:41:45.717 回答